[flang-commits] [flang] [flang][OpenMP] incorrect handling for local variable in OpenMP parallel workshare firstprivate(P) (PR #195616)
Tom Eccles via flang-commits
flang-commits at lists.llvm.org
Sun May 17 07:09:27 PDT 2026
================
@@ -356,9 +361,21 @@ static void parallelizeRegion(Region &sourceRegion, Region &targetRegion,
if (auto reloaded = rootMapping.lookupOrNull(v))
return nullptr;
Type ty = v.getType();
- Value alloc = fir::AllocaOp::create(allocaBuilder, loc, ty);
- fir::StoreOp::create(singleBuilder, loc, singleMapping.lookup(v), alloc);
- Value reloaded = fir::LoadOp::create(parallelBuilder, loc, ty, alloc);
+ // fir.alloca cannot wrap fir.ref, so for reference-typed values
+ // (e.g. results of dynamic fir.alloca ops) use fir.heap as the
+ // intermediary pointer type for the broadcast alloca.
----------------
tblah wrote:
I'm worried fir.ptr might lead to more pessimistic handling by fir::AliasAnalysis.
I think the problem here is trying to make a pointer to a pointer. Off the top of my head I can't remember another case where this is done in Flang. This suggests to me a broader design problem that is going unaddressed.
I don't quite understand the semantics being aimed for here: if sharing is intended then just map the original value. If you want a private copy then you need to duplicate the type which is being pointed to not just make a copy of the !fir.ref. It is by design that you can't have two references pointing at the same memory. I'd be worried about having one pointer and one ref engineered to be the same memory - I imagine this will break an alias analysis assumption somewhere.
https://github.com/llvm/llvm-project/pull/195616
More information about the flang-commits
mailing list