[flang-commits] [flang] [Flang][OpenMP] Fix crash and IR errors for user-defined reduction on allocatable variables (PR #186765)

Eugene Epshteyn via flang-commits flang-commits at lists.llvm.org
Mon Mar 16 06:27:34 PDT 2026


================
@@ -803,6 +804,185 @@ bool ReductionProcessor::processReductionArguments(
                          &redOperator.u)) {
         if (!ReductionProcessor::supportedIntrinsicProcReduction(
                 *reductionIntrinsic)) {
+          if (isByRef) {
+            // User-defined reduction on allocatable/pointer variable-
+            // we need a new declare_reduction for the boxed type, reusing
+            // the init value and combiner from the existing one. 
+            semantics::Symbol *sym = reductionIntrinsic->v.sym();
+            std::string baseName = sym->name().ToString();
+            mlir::ModuleOp module = builder.getModule();
+            auto existingDecl = module.lookupSymbol<OpType>(baseName);
+            if (!existingDecl) {
+              TODO(currentLocation,
+                   "User-defined reductions on allocatable or pointer "
+                   "variables: cannot find base reduction declaration");
+            }
+
+            std::string byrefName = getReductionName(
----------------
eugeneepshteyn wrote:

Please check if this could be `llvm::StringRef` or something else that may not need a full fledged `std::string` and potential heap allocation.

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


More information about the flang-commits mailing list