@@ -76,8 +76,9 @@ static llvm::cl::opt<bool> ClSanitizeGuardChecks(
7676RawAddress
7777CodeGenFunction::CreateTempAllocaWithoutCast (llvm::Type *Ty, CharUnits Align,
7878 const Twine &Name,
79- llvm::Value *ArraySize) {
80- auto Alloca = CreateTempAlloca (Ty, Name, ArraySize);
79+ llvm::Value *ArraySize,
80+ bool UseNondeterministicInit) {
81+ auto Alloca = CreateTempAlloca (Ty, Name, ArraySize, UseNondeterministicInit);
8182 Alloca->setAlignment (Align.getAsAlign ());
8283 return RawAddress (Alloca, Ty, Align, KnownNonNull);
8384}
@@ -87,8 +88,10 @@ CodeGenFunction::CreateTempAllocaWithoutCast(llvm::Type *Ty, CharUnits Align,
8788RawAddress CodeGenFunction::CreateTempAlloca (llvm::Type *Ty, CharUnits Align,
8889 const Twine &Name,
8990 llvm::Value *ArraySize,
90- RawAddress *AllocaAddr) {
91- auto Alloca = CreateTempAllocaWithoutCast (Ty, Align, Name, ArraySize);
91+ RawAddress *AllocaAddr,
92+ bool UseNondeterministicInit) {
93+ auto Alloca = CreateTempAllocaWithoutCast (Ty, Align, Name, ArraySize,
94+ UseNondeterministicInit);
9295 if (AllocaAddr)
9396 *AllocaAddr = Alloca;
9497 llvm::Value *V = Alloca.getPointer ();
@@ -115,22 +118,20 @@ RawAddress CodeGenFunction::CreateTempAlloca(llvm::Type *Ty, CharUnits Align,
115118// / CreateTempAlloca - This creates an alloca and inserts it into the entry
116119// / block if \p ArraySize is nullptr, otherwise inserts it at the current
117120// / insertion point of the builder.
118- llvm::AllocaInst *CodeGenFunction::CreateTempAlloca (llvm::Type *Ty,
119- const Twine &Name,
120- llvm::Value *ArraySize) {
121- LLVM_DEBUG ( llvm::dbgs () << " DEBUG: " << Name << " \n " ;);
121+ llvm::AllocaInst *
122+ CodeGenFunction::CreateTempAlloca (llvm::Type *Ty, const Twine &Name,
123+ llvm::Value *ArraySize,
124+ bool UseNondeterministicInit) {
122125 llvm::AllocaInst *Alloca;
123126 if (ArraySize)
124127 Alloca = Builder.CreateAlloca (Ty, ArraySize, Name);
125128 else {
126129 Alloca = new llvm::AllocaInst (Ty, CGM.getDataLayout ().getAllocaAddrSpace (),
127130 ArraySize, Name, AllocaInsertPt);
128- if (Ty->isIntegerTy ()) {
129- llvm::IRBuilder<> StoreFreezePoisonBuilder (Alloca->getContext ());
130- StoreFreezePoisonBuilder.SetInsertPoint (getPostAllocaInsertPoint ());
131- auto FreezePoison = StoreFreezePoisonBuilder.CreateFreeze (
132- llvm::PoisonValue::get (Ty), " freeze" );
133- StoreFreezePoisonBuilder.CreateStore (FreezePoison, Alloca);
131+ if (UseNondeterministicInit) {
132+ auto Freeze = new llvm::FreezeInst (llvm::PoisonValue::get (Ty),
133+ " freeze.poison" , AllocaInsertPt);
134+ new llvm::StoreInst (Freeze, Alloca, AllocaInsertPt);
134135 }
135136 }
136137 if (Allocas) {
@@ -156,16 +157,19 @@ RawAddress CodeGenFunction::CreateIRTemp(QualType Ty, const Twine &Name) {
156157}
157158
158159RawAddress CodeGenFunction::CreateMemTemp (QualType Ty, const Twine &Name,
159- RawAddress *Alloca) {
160+ RawAddress *Alloca,
161+ bool UseNondeterministicInit) {
160162 // FIXME: Should we prefer the preferred type alignment here?
161- return CreateMemTemp (Ty, getContext ().getTypeAlignInChars (Ty), Name, Alloca);
163+ return CreateMemTemp (Ty, getContext ().getTypeAlignInChars (Ty), Name, Alloca,
164+ UseNondeterministicInit);
162165}
163166
164167RawAddress CodeGenFunction::CreateMemTemp (QualType Ty, CharUnits Align,
165- const Twine &Name,
166- RawAddress *Alloca) {
167- RawAddress Result = CreateTempAlloca (ConvertTypeForMem (Ty), Align, Name,
168- /* ArraySize=*/ nullptr , Alloca);
168+ const Twine &Name, RawAddress *Alloca,
169+ bool UseNondeterministicInit) {
170+ RawAddress Result =
171+ CreateTempAlloca (ConvertTypeForMem (Ty), Align, Name,
172+ /* ArraySize=*/ nullptr , Alloca, UseNondeterministicInit);
169173
170174 if (Ty->isConstantMatrixType ()) {
171175 auto *ArrayTy = cast<llvm::ArrayType>(Result.getElementType ());
0 commit comments