[flang-commits] [flang] [Flang][OpenMP] Fix crash and IR errors for user-defined reduction on allocatable variables (PR #186765)
via flang-commits
flang-commits at lists.llvm.org
Sat Jul 4 01:29:52 PDT 2026
================
@@ -803,6 +804,185 @@ bool ReductionProcessor::processReductionArguments(
&redOperator.u)) {
if (!ReductionProcessor::supportedIntrinsicProcReduction(
*reductionIntrinsic)) {
+ if (isByRef) {
+ // create a new declare_reduction for the boxed type, reusing
+ // the existing init and combiner
+ semantics::Symbol *sym = reductionIntrinsic->v.sym();
+ llvm::StringRef baseName = {sym->name().begin(),
+ sym->name().size()};
+ 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(
+ baseName, builder.getKindMap(), redType, isByRef);
----------------
MattPD wrote:
Our reduction stack #207491-#207494 touches this same file. It gives reduction ops their symbol name via a helper, `getScopedUserReductionName` (scope-qualified base + per-type and by-ref suffix), used on both the directive materializer and the clause side so they bind.
The boxed op you create here takes the bare `sym->name()`, so once the trees combine it won't match the clause-side lookup, and boxed allocatable/pointer reductions won't lower. Whoever rebases second, could the boxed op here be named from `getScopedUserReductionName` (with the operand's type and `isByRef`) instead? Both `lookupSymbol<OpType>(baseName)` and `byrefName` would use it.
#207494 leaves exactly this case (boxed trivial-type allocatable/pointer) as a clean TODO gated by `isBoxedTrivialReduction`, precisely so #186765 can own it. The same rebase also shifts `declare-reduction-allocatable.f90` CHECK names to the scoped form. Happy to handle that naming on our side, or coordinate however's easiest.
https://github.com/llvm/llvm-project/pull/186765
More information about the flang-commits
mailing list