[flang-commits] [flang] [mlir] [OpenMP] [MLIR] [Flang] Replace all uses of variables in ALLOCATE directive to use new value which is created. (PR #212361)

Sairudra More via flang-commits flang-commits at lists.llvm.org
Wed Jul 29 19:59:41 PDT 2026


================
@@ -2905,19 +2905,43 @@ static void genWsloopClauses(
 //===----------------------------------------------------------------------===//
 // Code generation functions for leaf constructs
 //===----------------------------------------------------------------------===//
-static mlir::omp::AllocateDirOp genAllocateDirOp(
-    lower::AbstractConverter &converter, semantics::SemanticsContext &semaCtx,
-    lower::StatementContext &stmtCtx, lower::pft::Evaluation &eval,
-    mlir::Location loc, const ObjectList &objects, const ConstructQueue &queue,
-    ConstructQueue::const_iterator item) {
+
+static void genAllocateDirOp(lower::AbstractConverter &converter,
+                             semantics::SemanticsContext &semaCtx,
+                             lower::StatementContext &stmtCtx,
+                             lower::pft::Evaluation &eval, mlir::Location loc,
+                             const ObjectList &objects,
+                             const ConstructQueue &queue,
+                             ConstructQueue::const_iterator item) {
+  ObjectList supportedObjects;
+  supportedObjects.reserve(objects.size());
+  for (const Object &object : objects) {
+    const semantics::Symbol *sym = object.sym();
+    assert(sym && "Expected Symbol");
+    const semantics::Symbol &ultimate = sym->GetUltimate();
+    if (semantics::omp::IsCommonBlock(ultimate) ||
+        ultimate.attrs().test(semantics::Attr::SAVE)) {
----------------
Saieiei wrote:

`Attr::SAVE` misses an implicitly saved initialized local. At this head, an OpenMP 5.1 case using `integer :: counter = 100` and `allocator(omp_default_mem_alloc)` passes this guard, then loads from fresh allocated storage without copying the initializer. Could this use `evaluate::IsSaved(ultimate)` and add an implicit-SAVE regression test?

https://github.com/llvm/llvm-project/pull/212361


More information about the flang-commits mailing list