[clang] [OpenMP] Fix OpenMP reduction segfault with non-copyable types and user initializers. (PR #219265)
Alexey Bataev via cfe-commits
cfe-commits at lists.llvm.org
Sun Sep 13 10:39:38 PDT 2026
================
@@ -1135,8 +1135,32 @@ emitCombinerOrInitializer(CodeGenModule &CGM, QualType Ty,
Out->getType().getQualifiers(),
/*IsInitializer=*/true);
}
- if (CombinerInitializer)
- CGF.EmitIgnoredExpr(CombinerInitializer);
+ if (CombinerInitializer) {
+ // For non-trivial types with user initializers wrapped in StmtExpr,
+ // manually emit each statement to ensure constructor targets the right
+ // address.
+ if (!IsCombiner && isa<StmtExpr>(CombinerInitializer)) {
+ const auto *SE = cast<StmtExpr>(CombinerInitializer);
+ const CompoundStmt *CS = SE->getSubStmt();
+ AggValueSlot Slot = AggValueSlot::forAddr(
+ CGF.GetAddrOfLocalVar(Out), Ty.getQualifiers(),
+ AggValueSlot::IsDestructed, AggValueSlot::DoesNotNeedGCBarriers,
+ AggValueSlot::IsNotAliased, AggValueSlot::DoesNotOverlap);
+
+ // Emit each statement individually, passing slot to constructor.
+ for (const Stmt *S : CS->body()) {
+ const Stmt *Inner = S;
+ if (const auto *EWC = dyn_cast<ExprWithCleanups>(S))
+ Inner = EWC->getSubExpr();
+ if (const auto *CtorExpr = dyn_cast<CXXConstructExpr>(Inner))
+ CGF.EmitCXXConstructExpr(CtorExpr, Slot);
+ else
+ CGF.EmitStmt(S);
+ }
+ } else {
+ CGF.EmitIgnoredExpr(CombinerInitializer);
+ }
+ }
----------------
alexey-bataev wrote:
I think it should remain as is, no extra processing should be required, if everything is done correctly in Sema
https://github.com/llvm/llvm-project/pull/219265
More information about the cfe-commits
mailing list