Skip to content

Commit 053c1f5

Browse files
committed
[clang][wip] Refactoring nondeterministic initialization
Emission of nondeterministic initialization is moved to CodeGenFunction::EmitParmDecl and CodeGenFunction::EmitAutoVarAlloca.
1 parent 513db9e commit 053c1f5

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

clang/lib/CodeGen/CGDecl.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1564,9 +1564,7 @@ CodeGenFunction::EmitAutoVarAlloca(const VarDecl &D) {
15641564
// building the instruction so that it's there even in no-asserts
15651565
// builds.
15661566
address = CreateTempAlloca(allocaTy, allocaAlignment, D.getName(),
1567-
/*ArraySize=*/nullptr, &AllocaAddr,
1568-
allocaTy->isIntegerTy());
1569-
address.setIsNondeterministicInit(allocaTy->isIntegerTy());
1567+
/*ArraySize=*/nullptr, &AllocaAddr);
15701568

15711569
// Don't emit lifetime markers for MSVC catch parameters. The lifetime of
15721570
// the catch parameter starts in the catchpad instruction, and we can't
@@ -1599,6 +1597,18 @@ CodeGenFunction::EmitAutoVarAlloca(const VarDecl &D) {
15991597
} else {
16001598
assert(!emission.useLifetimeMarkers());
16011599
}
1600+
if (allocaTy->isIntegerTy()) {
1601+
if (HaveInsertPoint()) {
1602+
auto Freeze = Builder.CreateFreeze(llvm::PoisonValue::get(allocaTy),
1603+
"freeze.poison");
1604+
Builder.CreateStore(Freeze, address);
1605+
} else {
1606+
auto Freeze = new llvm::FreezeInst(llvm::PoisonValue::get(allocaTy),
1607+
"freeze.poison", AllocaInsertPt);
1608+
new llvm::StoreInst(Freeze, AllocaAddr.getPointer(), AllocaInsertPt);
1609+
}
1610+
address.setIsNondeterministicInit(allocaTy->isIntegerTy());
1611+
}
16021612
}
16031613
} else {
16041614
EnsureInsertPoint();
@@ -2646,7 +2656,7 @@ void CodeGenFunction::EmitParmDecl(const VarDecl &D, ParamValue Arg,
26462656
} else {
26472657
// Otherwise, create a temporary to hold the value.
26482658
DeclPtr = CreateMemTemp(Ty, getContext().getDeclAlign(&D),
2649-
D.getName() + ".addr", &AllocaPtr, false);
2659+
D.getName() + ".addr", &AllocaPtr);
26502660
DeclPtr.setIsNondeterministicInit(true);
26512661
}
26522662
DoStore = true;

0 commit comments

Comments
 (0)