[flang-commits] [flang] [flang][OpenMP] Support user-defined declare reduction with derived types (PR #184897)

Tom Eccles via flang-commits flang-commits at lists.llvm.org
Tue Mar 24 04:22:03 PDT 2026


================
@@ -636,6 +618,18 @@ void PopulateInitAndCleanupRegionsHelper::initAndCleanupBoxchar(
 void PopulateInitAndCleanupRegionsHelper::initAndCleanupUnboxedDerivedType(
     bool needsInitialization) {
   builder.setInsertionPointToStart(initBlock);
+  // For reductions with a user-provided init value, store it into the
+  // private variable. Insert after the init value's defining op to
+  // maintain SSA dominance (the init value was generated by the
+  // callback before populateByRefInitAndCleanupRegions was called).
+  if (scalarInitValue && isReduction(kind)) {
+    mlir::OpBuilder::InsertionGuard guard(builder);
+    if (auto *defOp = scalarInitValue.getDefiningOp())
+      builder.setInsertionPointAfter(defOp);
+    else
+      builder.setInsertionPointToEnd(initBlock);
+    fir::StoreOp::create(builder, loc, scalarInitValue, allocatedPrivVarArg);
----------------
tblah wrote:

Elsewhere in lowering flang seems to generate hlfir.assign for assignments to a whole derived type

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


More information about the flang-commits mailing list