[llvm] [ASan] Add metadata to renamed instructions so ASan doesn't use the i… (PR #119387)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 10 07:27:11 PST 2024
https://github.com/gbMattN updated https://github.com/llvm/llvm-project/pull/119387
>From 8781ff2355750ae61d140620b1f6862537de07e3 Mon Sep 17 00:00:00 2001
From: gbMattN <matthew.nagy at sony.com>
Date: Tue, 10 Dec 2024 15:01:37 +0000
Subject: [PATCH] [ASan] Add metadata to renamed instructions so ASan doesn't
use the incorrect name
---
llvm/lib/IR/ValueSymbolTable.cpp | 8 ++++++++
llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp | 7 ++++++-
2 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/llvm/lib/IR/ValueSymbolTable.cpp b/llvm/lib/IR/ValueSymbolTable.cpp
index a020acf22a96c5..81bb3f3c5a5e35 100644
--- a/llvm/lib/IR/ValueSymbolTable.cpp
+++ b/llvm/lib/IR/ValueSymbolTable.cpp
@@ -123,6 +123,14 @@ ValueName *ValueSymbolTable::createValueName(StringRef Name, Value *V) {
}
// Otherwise, there is a naming conflict. Rename this value.
+ // If we are renaming an instruction, ASan needs to know for it to serialize
+ // properly
+ if (auto *I = dyn_cast<Instruction>(V)) {
+ MDString *trueNameMetadata = MDString::get(V->getContext(), Name);
+ llvm::MDTuple *tuple =
+ llvm::MDTuple::get(V->getContext(), trueNameMetadata);
+ I->setMetadata("OriginalName", tuple);
+ }
SmallString<256> UniqueName(Name.begin(), Name.end());
return makeUniqueName(V, UniqueName);
}
diff --git a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
index cb84588318496c..c696cc38167cd4 100644
--- a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -3430,7 +3430,12 @@ void FunctionStackPoisoner::processStaticAllocas() {
SmallVector<ASanStackVariableDescription, 16> SVD;
SVD.reserve(AllocaVec.size());
for (AllocaInst *AI : AllocaVec) {
- ASanStackVariableDescription D = {AI->getName().data(),
+ std::string Name = AI->getName().data();
+ if (AI->hasMetadata("OriginalName")) {
+ MDTuple *tuple = dyn_cast<MDTuple>(AI->getMetadata("OriginalName"));
+ Name = dyn_cast<MDString>(tuple->getOperand(0))->getString();
+ }
+ ASanStackVariableDescription D = {Name.c_str(),
ASan.getAllocaSizeInBytes(*AI),
0,
AI->getAlign().value(),
More information about the llvm-commits
mailing list