Skip to content

Commit e923490

Browse files
committed
Add OVE to capture side effecting arguments in init list
1 parent c5f2a1f commit e923490

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3219,9 +3219,18 @@ bool SemaHLSL::TransformInitList(const InitializedEntity &Entity,
32193219
BuildFlattenedTypeList(InitTy, DestTypes);
32203220

32213221
llvm::SmallVector<Expr *, 16> ArgExprs;
3222-
for (Expr *Arg : Init->inits())
3223-
if (!BuildInitializerList(SemaRef, Ctx, Arg, ArgExprs, DestTypes))
3222+
for (unsigned I = 0; I < Init->getNumInits(); ++I) {
3223+
Expr *E = Init->getInit(I);
3224+
if (E->HasSideEffects(Ctx)) {
3225+
QualType Ty = E->getType();
3226+
if (auto *RTy = Ty->getAs<RecordType>())
3227+
E = new (Ctx) MaterializeTemporaryExpr(Ty, E, E->isLValue());
3228+
E = new (Ctx) OpaqueValueExpr(E->getBeginLoc(), Ty, E->getValueKind());
3229+
Init->setInit(I, E);
3230+
}
3231+
if (!BuildInitializerList(SemaRef, Ctx, E, ArgExprs, DestTypes))
32243232
return false;
3233+
}
32253234

32263235
if (DestTypes.size() != ArgExprs.size()) {
32273236
int TooManyOrFew = ArgExprs.size() > DestTypes.size() ? 1 : 0;

0 commit comments

Comments
 (0)