diff options
author | Vitaly Buka <vitalybuka@google.com> | 2022-08-29 20:43:08 -0700 |
---|---|---|
committer | Vitaly Buka <vitalybuka@google.com> | 2022-08-31 13:12:17 -0700 |
commit | 960e7a5513267b38a07405931300bbf40ddf1902 (patch) | |
tree | 6ca8ffb83bf6ac9a852e21f3a0273eb3d2c765ed /clang/lib/CodeGen/CGClass.cpp | |
parent | d7474bef779ab9848d48e2a0625778b78eac6fee (diff) | |
download | llvm-960e7a5513267b38a07405931300bbf40ddf1902.zip llvm-960e7a5513267b38a07405931300bbf40ddf1902.tar.gz llvm-960e7a5513267b38a07405931300bbf40ddf1902.tar.bz2 |
[msan] Use Debug Info to point to affected fields
Reviewed By: kstoimenov
Differential Revision: https://reviews.llvm.org/D132909
Diffstat (limited to 'clang/lib/CodeGen/CGClass.cpp')
-rw-r--r-- | clang/lib/CodeGen/CGClass.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CGClass.cpp b/clang/lib/CodeGen/CGClass.cpp index ec4d8e5..4a952b9 100644 --- a/clang/lib/CodeGen/CGClass.cpp +++ b/clang/lib/CodeGen/CGClass.cpp @@ -1649,6 +1649,29 @@ namespace { } }; + class DeclAsInlineDebugLocation { + CGDebugInfo *DI; + llvm::MDNode *InlinedAt; + llvm::Optional<ApplyDebugLocation> Location; + + public: + DeclAsInlineDebugLocation(CodeGenFunction &CGF, const NamedDecl &Decl) + : DI(CGF.getDebugInfo()) { + if (!DI) + return; + InlinedAt = DI->getInlinedAt(); + DI->setInlinedAt(CGF.Builder.getCurrentDebugLocation()); + Location.emplace(CGF, Decl.getLocation()); + } + + ~DeclAsInlineDebugLocation() { + if (!DI) + return; + Location.reset(); + DI->setInlinedAt(InlinedAt); + } + }; + static void EmitSanitizerDtorCallback( CodeGenFunction &CGF, StringRef Name, llvm::Value *Ptr, llvm::Optional<CharUnits::QuantityType> PoisonSize = {}) { @@ -1699,6 +1722,9 @@ namespace { if (!BaseSize.isPositive()) return; + // Use the base class declaration location as inline DebugLocation. All + // fields of the class are destroyed. + DeclAsInlineDebugLocation InlineHere(CGF, *BaseClass); EmitSanitizerDtorFieldsCallback(CGF, Addr.getPointer(), BaseSize.getQuantity()); @@ -1748,6 +1774,9 @@ namespace { if (!PoisonSize.isPositive()) return; + // Use the top field declaration location as inline DebugLocation. + DeclAsInlineDebugLocation InlineHere( + CGF, **std::next(Dtor->getParent()->field_begin(), StartIndex)); EmitSanitizerDtorFieldsCallback(CGF, OffsetPtr, PoisonSize.getQuantity()); // Prevent the current stack frame from disappearing from the stack trace. |