[flang-commits] [flang] [Flang][OpenMP] Fix crash privatizing USE'd module variable in BLOCK (PR #182060)

Tom Eccles via flang-commits flang-commits at lists.llvm.org
Thu Feb 19 01:57:30 PST 2026


================
@@ -616,6 +616,17 @@ void DataSharingProcessor::privatizeSymbol(
     copyFirstPrivateSymbol(symToPrivatize);
     return;
   }
+  // Module variables accessed via USE inside nested BLOCKs may not yet
+  // be instantiated when the enclosing OpenMP construct's privatization
+  // runs. Instantiate them now so the host symbol box will be available.
+  const auto &ultimate = symToPrivatize->GetUltimate();
+  if (ultimate.owner().kind() == semantics::Scope::Kind::Module &&
+      !symTable.lookupSymbol(ultimate)) {
+    Fortran::lower::AggregateStoreMap storeMap;
+    Fortran::lower::instantiateVariable(
+        converter, Fortran::lower::pft::Variable{ultimate, /*global=*/true},
+        symTable, storeMap);
+  }
 
   Fortran::lower::privatizeSymbol<mlir::omp::PrivateClauseOp,
----------------
tblah wrote:

Fortran::lower::privatizeSymbol is also used for do concurrent in base Fortran. Is a USE statement legal there too? Perhaps the global symbol needs handling in the shared helper.

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


More information about the flang-commits mailing list