Skip to content

Commit c15ec2f

Browse files
committed
Now only emit metadata when using a ASan, and tag it with an enum rather than a string
1 parent 25efafa commit c15ec2f

File tree

4 files changed

+16
-18
lines changed

4 files changed

+16
-18
lines changed

clang/lib/CodeGen/CGExpr.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,14 @@ llvm::AllocaInst *CodeGenFunction::CreateTempAlloca(llvm::Type *Ty,
137137
Alloca =
138138
new llvm::AllocaInst(Ty, CGM.getDataLayout().getAllocaAddrSpace(),
139139
ArraySize, Name, AllocaInsertPt->getIterator());
140+
if (Alloca->getName() != Name.str() &&
141+
SanOpts.Mask & SanitizerKind::Address) {
142+
143+
llvm::LLVMContext &ctx = Alloca->getContext();
144+
llvm::MDString *trueNameMetadata = llvm::MDString::get(ctx, Name.str());
145+
llvm::MDTuple *tuple = llvm::MDTuple::get(ctx, trueNameMetadata);
146+
Alloca->setMetadata(llvm::LLVMContext::MD_unaltered_name, tuple);
147+
}
140148
if (Allocas) {
141149
Allocas->Add(Alloca);
142150
}

llvm/include/llvm/IR/FixedMetadataKinds.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,4 @@ LLVM_FIXED_MD_KIND(MD_DIAssignID, "DIAssignID", 38)
5353
LLVM_FIXED_MD_KIND(MD_coro_outside_frame, "coro.outside.frame", 39)
5454
LLVM_FIXED_MD_KIND(MD_mmra, "mmra", 40)
5555
LLVM_FIXED_MD_KIND(MD_noalias_addrspace, "noalias.addrspace", 41)
56+
LLVM_FIXED_MD_KIND(MD_unaltered_name, "unaltered.name", 42)

llvm/lib/IR/ValueSymbolTable.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,6 @@ ValueName *ValueSymbolTable::createValueName(StringRef Name, Value *V) {
123123
}
124124

125125
// Otherwise, there is a naming conflict. Rename this value.
126-
// If we are renaming an instruction, ASan needs to know for it to serialize
127-
// properly
128-
if (auto *I = dyn_cast<Instruction>(V)) {
129-
MDString *trueNameMetadata = MDString::get(V->getContext(), Name);
130-
llvm::MDTuple *tuple =
131-
llvm::MDTuple::get(V->getContext(), trueNameMetadata);
132-
I->setMetadata("OriginalName", tuple);
133-
}
134126
SmallString<256> UniqueName(Name.begin(), Name.end());
135127
return makeUniqueName(V, UniqueName);
136128
}

llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3430,18 +3430,15 @@ void FunctionStackPoisoner::processStaticAllocas() {
34303430
SmallVector<ASanStackVariableDescription, 16> SVD;
34313431
SVD.reserve(AllocaVec.size());
34323432
for (AllocaInst *AI : AllocaVec) {
3433-
const char* Name = AI->getName().data();
3434-
if (AI->hasMetadata("OriginalName")) {
3435-
MDTuple *tuple = dyn_cast<MDTuple>(AI->getMetadata("OriginalName"));
3433+
const char *Name = AI->getName().data();
3434+
if (AI->hasMetadata(LLVMContext::MD_unaltered_name)) {
3435+
MDTuple *tuple =
3436+
dyn_cast<MDTuple>(AI->getMetadata(LLVMContext::MD_unaltered_name));
34363437
Name = dyn_cast<MDString>(tuple->getOperand(0))->getString().data();
34373438
}
3438-
ASanStackVariableDescription D = {Name,
3439-
ASan.getAllocaSizeInBytes(*AI),
3440-
0,
3441-
AI->getAlign().value(),
3442-
AI,
3443-
0,
3444-
0};
3439+
ASanStackVariableDescription D = {
3440+
Name, ASan.getAllocaSizeInBytes(*AI), 0, AI->getAlign().value(), AI, 0,
3441+
0};
34453442
SVD.push_back(D);
34463443
}
34473444

0 commit comments

Comments
 (0)