Skip to content

Commit e0f96d5

Browse files
committed
[clang][wip] Add nondeterministic initialization at alloca generation
1 parent 4f8f3bd commit e0f96d5

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

clang/lib/CodeGen/CGExpr.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include "llvm/IR/MatrixBuilder.h"
4242
#include "llvm/Passes/OptimizationLevel.h"
4343
#include "llvm/Support/ConvertUTF.h"
44+
#include "llvm/Support/Debug.h"
4445
#include "llvm/Support/MathExtras.h"
4546
#include "llvm/Support/Path.h"
4647
#include "llvm/Support/SaveAndRestore.h"
@@ -50,6 +51,8 @@
5051
#include <optional>
5152
#include <string>
5253

54+
#define DEBUG_TYPE "CGExpr"
55+
5356
using namespace clang;
5457
using namespace CodeGen;
5558

@@ -115,12 +118,21 @@ RawAddress CodeGenFunction::CreateTempAlloca(llvm::Type *Ty, CharUnits Align,
115118
llvm::AllocaInst *CodeGenFunction::CreateTempAlloca(llvm::Type *Ty,
116119
const Twine &Name,
117120
llvm::Value *ArraySize) {
121+
LLVM_DEBUG(llvm::dbgs() << "DEBUG: " << Name << "\n";);
118122
llvm::AllocaInst *Alloca;
119123
if (ArraySize)
120124
Alloca = Builder.CreateAlloca(Ty, ArraySize, Name);
121-
else
125+
else {
122126
Alloca = new llvm::AllocaInst(Ty, CGM.getDataLayout().getAllocaAddrSpace(),
123127
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);
134+
}
135+
}
124136
if (Allocas) {
125137
Allocas->Add(Alloca);
126138
}

0 commit comments

Comments
 (0)