[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
Wed Mar 18 03:14:26 PDT 2026
================
@@ -527,8 +409,16 @@ bool ClauseProcessor::processInitializer(
"OpenMP reduction allocation for dynamic length character");
}
}
- // If ompOrig is already a reference, we can use it directly
- if (fir::isa_ref_type(ompOrigType)) {
+ // For by-ref reductions, the init block has two arguments:
+ // arg0 = mold/original, arg1 = private allocation.
+ // omp_priv must map to arg1 (the private copy), not arg0.
+ if (name == "omp_priv" && fir::isa_ref_type(ompOrigType)) {
+ mlir::Block *initBlock = builder.getInsertionBlock();
+ if (initBlock->getNumArguments() > 1)
+ addr = initBlock->getArgument(1);
+ else
+ addr = ompOrig;
+ } else if (fir::isa_ref_type(ompOrigType)) {
----------------
tblah wrote:
Please fix the API of the callback type. I know it wasn't your code but I think it is making your code much harder to understand. Overloading the same value to sometimes represent the mold sometimes and the private allocation at other times is way too hard to reason about.
https://github.com/llvm/llvm-project/pull/184897
More information about the flang-commits
mailing list