================
@@ -1575,6 +1606,37 @@ void CodeGenFunction::EmitOMPReductionClauseInit(
auto *IPriv = Privates.begin();
for (const Expr *IRef : Shareds) {
const auto *PrivateVD =
cast<VarDecl>(cast<DeclRefExpr>(*IPriv)->getDecl());
+ const BindingDecl *BD = nullptr;
+ if (const auto *DRE = dyn_cast<DeclRefExpr>(IRef->IgnoreParenImpCasts()))
+ BD = dyn_cast<BindingDecl>(DRE->getDecl());
+ if (BD) {
+ // Emit the private VarDecl with reduction initialization.
+ EmitDecl(*PrivateVD);
+ Address PrivateAddr = GetAddrOfLocalVar(PrivateVD);
+
+ // Register the BindingDecl with the private address.
+ bool IsRegistered = PrivateScope.addPrivate(BD, PrivateAddr);
+ assert(IsRegistered && "private binding already registered as private");
+ (void)IsRegistered;
+
+ // Get the original BindingDecl address for LHSVD registration.
+ DeclRefExpr BindingDRE(getContext(), const_cast<BindingDecl *>(BD),
+ /*RefersToEnclosingVariableOrCapture=*/true,
+ BD->getType(), VK_LValue, IRef->getExprLoc());
+ LValue OriginalLVal = EmitLValue(&BindingDRE);
+ Address OriginalAddr = OriginalLVal.getAddress();
+
+ // Register LHSVD/RHSVD for reduction operation.
+ const auto *LHSVD = cast<VarDecl>(cast<DeclRefExpr>(*ILHS)->getDecl());
+ const auto *RHSVD = cast<VarDecl>(cast<DeclRefExpr>(*IRHS)->getDecl());
+ PrivateScope.addPrivate(LHSVD, OriginalAddr);
+ PrivateScope.addPrivate(RHSVD, PrivateAddr);
+ ++Count;
+ ++ILHS;
+ ++IRHS;
+ ++IPriv;
+ continue;
----------------
zahiraam wrote:
The `BindingDecl` path cannot use `RedCG.emitSharedOrigLValue(`) because that
calls `EmitOMPSharedLValue()` which crashes when trying to emit a `BindingDecl`
reference in the outlined region (the `DecompositionDecl` context is broken).
Instead, we emit the original `BindingDecl` address directly and
register`LHSVD/RHSVD` manually, which achieves the same writeback effect. I've
added detailed comments explaining this limitation.
https://github.com/llvm/llvm-project/pull/190832
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits