[compiler-rt] [llvm] [msan] Add experimental '-mllvm -msan-embed-faulting-instruction' and MSAN_OPTIONS=print_faulting_instruction (PR #136539)
Florian Mayer via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 21 09:53:59 PDT 2025
================
@@ -1455,21 +1513,51 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
// correct origin.
bool Combine = !MS.TrackOrigins;
Instruction *Instruction = InstructionChecks.front().OrigIns;
+
+ Value *InstName = nullptr;
+ if (ClEmbedFaultingInst >= 1) {
+ IRBuilder<> IRB0(Instruction);
+ std::string str;
+ StringRef InstNameStrRef;
+
+ // Dumping the full instruction is expensive because the operands etc.
+ // likely make the string unique per instruction instance, hence we
+ // offer a choice whether to only print the instruction name.
+ if (ClEmbedFaultingInst >= 2) {
+ llvm::raw_string_ostream buf(str);
+ Instruction->print(buf);
+ InstNameStrRef = StringRef(str);
+ } else if (ClEmbedFaultingInst >= 1) {
+ if (CallInst *CI = dyn_cast<CallInst>(Instruction)) {
+ if (CI->getCalledFunction()) {
+ Twine description = "call " + CI->getCalledFunction()->getName();
+ SmallVector<char> maybeBuf;
+ InstNameStrRef = description.toStringRef(maybeBuf);
+ } else {
+ InstNameStrRef = StringRef("Unknown call");
+ }
+ } else {
+ InstNameStrRef = StringRef(Instruction->getOpcodeName());
+ }
+ }
+
+ InstName = IRB0.CreateGlobalString(InstNameStrRef);
+ }
+
Value *Shadow = nullptr;
for (const auto &ShadowData : InstructionChecks) {
assert(ShadowData.OrigIns == Instruction);
IRBuilder<> IRB(Instruction);
Value *ConvertedShadow = ShadowData.Shadow;
-
----------------
fmayer wrote:
unrelated change
https://github.com/llvm/llvm-project/pull/136539
More information about the llvm-commits
mailing list