)]}'
{
  "commit": "670d37f4653c5374d43809800cdfbab2a6d9c4fa",
  "tree": "d3b0dbc2db9c00392aa6c2605a66b9e680718217",
  "parents": [
    "edc6da7c161d0ceedbda45df61532651d111a0d3"
  ],
  "author": {
    "name": "Slava Zakharin",
    "email": "szakharin@nvidia.com",
    "time": "Fri Aug 28 15:01:46 2026 -0700"
  },
  "committer": {
    "name": "Copybara-Service",
    "email": "copybara-worker@google.com",
    "time": "Fri Aug 28 15:10:29 2026 -0700"
  },
  "message": "[flang][OpenACC] Changed memory management for private POINTERs. (#219052)\n\nThe motivating example:\n```\n!$acc parallel loop private(ptr) present(target_data)\n  do i \u003d 1, 128\n     ptr \u003d\u003e target_data(i)%array\n     ptr(...) \u003d ...\n```\n\nThe OpenACC privatization recipe was allocating private data\nfor `ptr`, storing it in `ptr` private descriptor and then\ntrying to deallocate `ptr-\u003ebase_addr` at the end of the region.\n\n`ptr-\u003ebase_addr` is pointing to `target_data(i)%array` that is allocated\nin device global memory and it is illegal to `free()` it in the device\ncode.\n\nThe `destroy` part of the recipe can only `free()` the private data\nthat was originally allocated in the `init` part.\n\nThis approach works well for the two most common case.\n\nCase 1: `ptr` is originally unassociated and it is used to point\nto some target data (the example above).\nCase 2: `ptr` is originally associated and it is used as a normal\nprivate variable for storing something into it without reassociating\n`ptr` to some other data.\n\nThis change, on the other hand, breaks the following case:\n```\nallocate(ptr(10))\n!$acc parallel private(ptr)...\ndeallocate(ptr)\nptr \u003d\u003e ...\n```\n\nThe private memory for `ptr` data may be allocated from the host\nusing CUDA runtime or driver API, and it is illegal to deallocate\nit via `free()` which flang-rt\u0027s implementation is using.\nMoreover, flang-rt\u0027s implementation of `DEALLOCATE` assumes\nthere is an 8-byte footer after the data payload that it uses\nto verify whether a `POINTER` deallocation is valid. OpenACC\nprivatization recipe uses `fir.allocmem` that does not create\nthe footer, so flang-rt may read past the allocated data\nand crash the kernel.\n\nThe reference compiler implements `DEALLOCATE` as `free()`, so\nthe compute-sanitizer reports invalid `free()` errors, though,\nw/o the sanitizer the kernel silently passes.\n\nFlang\u0027s implementation either fails in `DEALLOCATE` runtime with\n`DEALLOCATE of a pointer that is not the whole content of a pointer\nALLOCATE`\nerror or crashes the kernel due to accessing past the allocated memory.\n\nOpenACC spec does not explicitly specify what should happen in this\ncase,\nso I suggest that Flang\u0027s implementation always reports a runtime error\nwhen program tries to deallocate the private data. This is left for\nfuture improvement.\n\nAssisted-by: Cursor\nGitOrigin-RevId: 02c5537c2569b54ee0eb6d0c25dcb9b485fb7406\n",
  "tree_diff": [
    {
      "type": "modify",
      "old_id": "ae47805a1af4205e42dd7db9e03dec3b2fd4a758",
      "old_mode": 33188,
      "old_path": "include/flang/Optimizer/OpenACC/Support/FIROpenACCTypeInterfaces.h",
      "new_id": "4e4e0d5f2c6f2ee26b64b6386259e68971c9fe18",
      "new_mode": 33188,
      "new_path": "include/flang/Optimizer/OpenACC/Support/FIROpenACCTypeInterfaces.h"
    },
    {
      "type": "modify",
      "old_id": "e7e522e8e15706354def4d6edeba6b1b8027b1ec",
      "old_mode": 33188,
      "old_path": "lib/Optimizer/OpenACC/Support/FIROpenACCTypeInterfaces.cpp",
      "new_id": "0580eedcac51dfaba6f0fb406f2162f2a9a1da4a",
      "new_mode": 33188,
      "new_path": "lib/Optimizer/OpenACC/Support/FIROpenACCTypeInterfaces.cpp"
    },
    {
      "type": "modify",
      "old_id": "f0ce7bb4e57c5527967617a8954be1f6ced7779e",
      "old_mode": 33188,
      "old_path": "lib/Optimizer/OpenACC/Support/FIROpenACCUtils.cpp",
      "new_id": "404939f2a3e34b0c76d5d90ea5aa04cdde4b1174",
      "new_mode": 33188,
      "new_path": "lib/Optimizer/OpenACC/Support/FIROpenACCUtils.cpp"
    },
    {
      "type": "modify",
      "old_id": "f5200f70a3ba871cc26e53f3b361ee70e330d9a4",
      "old_mode": 33188,
      "old_path": "test/Fir/OpenACC/recipe-populate-private.mlir",
      "new_id": "c5e37db7d450b401b0ac7bc1a8433f16152b75c7",
      "new_mode": 33188,
      "new_path": "test/Fir/OpenACC/recipe-populate-private.mlir"
    },
    {
      "type": "modify",
      "old_id": "67709f1e9e7cea61e43486accee6f4917010e3ca",
      "old_mode": 33188,
      "old_path": "test/Lower/OpenACC/acc-private.f90",
      "new_id": "fdebdc2ed6f2a4824d40645feb96aaa8f639c6e8",
      "new_mode": 33188,
      "new_path": "test/Lower/OpenACC/acc-private.f90"
    },
    {
      "type": "modify",
      "old_id": "f4fc0910e678aff208f02c7f44998f5d8dbcbc42",
      "old_mode": 33188,
      "old_path": "test/Lower/OpenACC/acc-reduction.f90",
      "new_id": "de60d4dfd432fe9a46acf515d9b2affc59aeb4db",
      "new_mode": 33188,
      "new_path": "test/Lower/OpenACC/acc-reduction.f90"
    },
    {
      "type": "modify",
      "old_id": "12eecb6cab6725e295515ee7f9577a8c3f18f5b9",
      "old_mode": 33188,
      "old_path": "test/Transforms/OpenACC/acc-recipe-materialization-firstprivate.fir",
      "new_id": "1a90ea30cf2d3ee666541d287ca49cea77199d90",
      "new_mode": 33188,
      "new_path": "test/Transforms/OpenACC/acc-recipe-materialization-firstprivate.fir"
    },
    {
      "type": "modify",
      "old_id": "97c8236472f74e6c8d0767e84e41079476335148",
      "old_mode": 33188,
      "old_path": "test/Transforms/OpenACC/acc-recipe-materialization-private.fir",
      "new_id": "10a97f080ec9761d5dd3cb51147693368d50435c",
      "new_mode": 33188,
      "new_path": "test/Transforms/OpenACC/acc-recipe-materialization-private.fir"
    }
  ]
}
