[compiler-rt] 960e7a5 - [msan] Use Debug Info to point to affected fields
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 31 13:12:35 PDT 2022
Author: Vitaly Buka
Date: 2022-08-31T13:12:17-07:00
New Revision: 960e7a5513267b38a07405931300bbf40ddf1902
URL: https://github.com/llvm/llvm-project/commit/960e7a5513267b38a07405931300bbf40ddf1902
DIFF: https://github.com/llvm/llvm-project/commit/960e7a5513267b38a07405931300bbf40ddf1902.diff
LOG: [msan] Use Debug Info to point to affected fields
Reviewed By: kstoimenov
Differential Revision: https://reviews.llvm.org/D132909
Added:
Modified:
clang/lib/CodeGen/CGClass.cpp
clang/test/CodeGenCXX/sanitize-dtor-bit-field.cpp
clang/test/CodeGenCXX/sanitize-dtor-callback.cpp
clang/test/CodeGenCXX/sanitize-dtor-derived-class.cpp
clang/test/CodeGenCXX/sanitize-dtor-nontrivial-virtual-base.cpp
clang/test/CodeGenCXX/sanitize-dtor-trivial-base.cpp
clang/test/CodeGenCXX/sanitize-dtor-trivial.cpp
clang/test/CodeGenCXX/sanitize-dtor-vtable.cpp
compiler-rt/test/msan/dtor-base-access.cpp
compiler-rt/test/msan/use-after-dtor.cpp
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/CGClass.cpp b/clang/lib/CodeGen/CGClass.cpp
index ec4d8e50a356..4a952b9abd55 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.
diff --git a/clang/test/CodeGenCXX/sanitize-dtor-bit-field.cpp b/clang/test/CodeGenCXX/sanitize-dtor-bit-field.cpp
index 94571d449380..5bb48ac102ee 100644
--- a/clang/test/CodeGenCXX/sanitize-dtor-bit-field.cpp
+++ b/clang/test/CodeGenCXX/sanitize-dtor-bit-field.cpp
@@ -83,7 +83,7 @@ Adjacent ad;
// CHECK-LABEL: !DIFile{{.*}}cpp
-// CHECK-DAG: ![[DI1]] = {{.*}}line: [[@LINE-68]]
-// CHECK-DAG: ![[DI2]] = {{.*}}line: [[@LINE-53]]
-// CHECK-DAG: ![[DI3]] = {{.*}}line: [[@LINE-41]]
-// CHECK-DAG: ![[DI4]] = {{.*}}line: [[@LINE-28]]
+// CHECK-DAG: ![[DI1]] = {{.*}}line: [[@LINE-78]]
+// CHECK-DAG: ![[DI2]] = {{.*}}line: [[@LINE-54]]
+// CHECK-DAG: ![[DI3]] = {{.*}}line: [[@LINE-46]]
+// CHECK-DAG: ![[DI4]] = {{.*}}line: [[@LINE-30]]
diff --git a/clang/test/CodeGenCXX/sanitize-dtor-callback.cpp b/clang/test/CodeGenCXX/sanitize-dtor-callback.cpp
index 18c6417001fd..e4a204eab324 100644
--- a/clang/test/CodeGenCXX/sanitize-dtor-callback.cpp
+++ b/clang/test/CodeGenCXX/sanitize-dtor-callback.cpp
@@ -70,6 +70,6 @@ Defaulted_Non_Trivial def_non_trivial;
// CHECK-LABEL: !DIFile{{.*}}cpp
-// CHECK-DAG: ![[DI1]] = {{.*}}line: [[@LINE-64]]
-// CHECK-DAG: ![[DI2]] = {{.*}}line: [[@LINE-55]]
-// CHECK-DAG: ![[DI3]] = {{.*}}line: [[@LINE-33]]
+// CHECK-DAG: ![[DI1]] = {{.*}}line: [[@LINE-65]]
+// CHECK-DAG: ![[DI2]] = {{.*}}line: [[@LINE-56]]
+// CHECK-DAG: ![[DI3]] = {{.*}}line: [[@LINE-34]]
diff --git a/clang/test/CodeGenCXX/sanitize-dtor-derived-class.cpp b/clang/test/CodeGenCXX/sanitize-dtor-derived-class.cpp
index 1d5accb8bfd0..e3d83a9d06a5 100644
--- a/clang/test/CodeGenCXX/sanitize-dtor-derived-class.cpp
+++ b/clang/test/CodeGenCXX/sanitize-dtor-derived-class.cpp
@@ -50,17 +50,19 @@ Derived d;
// Poison members and vtable ptr.
// CHECK-LABEL: define {{.*}}BaseD2Ev
// CHECK: call void @__sanitizer_dtor_callback_fields({{.*}}, !dbg ![[DI1:[0-9]+]]
-// CHECK: call void @__sanitizer_dtor_callback_vptr({{.*}}){{.*}}, !dbg ![[DI1]]
+// CHECK: call void @__sanitizer_dtor_callback_vptr({{.*}}){{.*}}, !dbg ![[DI2:[0-9]+]]
// CHECK: ret void
// Poison members and destroy non-virtual base.
// CHECK-LABEL: define {{.*}}DerivedD2Ev
// CHECK: call void @__sanitizer_dtor_callback_fields({{.*}}, !dbg ![[DI3:[0-9]+]]
// CHECK: call void {{.*}}BaseD2Ev
-// CHECK: call void @__sanitizer_dtor_callback_vptr({{.*}}){{.*}}, !dbg ![[DI3]]
+// CHECK: call void @__sanitizer_dtor_callback_vptr({{.*}}){{.*}}, !dbg ![[DI4:[0-9]+]]
// CHECK: ret void
// CHECK-LABEL: !DIFile{{.*}}cpp
-// CHECK-DAG: ![[DI1]] = {{.*}}line: [[@LINE-49]]
-// CHECK-DAG: ![[DI3]] = {{.*}}line: [[@LINE-39]]
+// CHECK-DAG: ![[DI1]] = {{.*}}line: [[@LINE-55]]
+// CHECK-DAG: ![[DI2]] = {{.*}}line: [[@LINE-50]]
+// CHECK-DAG: ![[DI3]] = {{.*}}line: [[@LINE-46]]
+// CHECK-DAG: ![[DI4]] = {{.*}}line: [[@LINE-41]]
diff --git a/clang/test/CodeGenCXX/sanitize-dtor-nontrivial-virtual-base.cpp b/clang/test/CodeGenCXX/sanitize-dtor-nontrivial-virtual-base.cpp
index adbe77fc659b..0795e75c3642 100644
--- a/clang/test/CodeGenCXX/sanitize-dtor-nontrivial-virtual-base.cpp
+++ b/clang/test/CodeGenCXX/sanitize-dtor-nontrivial-virtual-base.cpp
@@ -62,32 +62,34 @@ Derived d;
// poison 2 ints
// CHECK-LABEL: define {{.*}}ZN11VirtualBaseD2Ev
// CHECK: call void @__sanitizer_dtor_callback_fields({{.*}}, i64 8){{.*}}, !dbg ![[DI1:[0-9]+]]
-// CHECK: call void @__sanitizer_dtor_callback_vptr({{.*}}){{.*}}, !dbg ![[DI1]]
+// CHECK: call void @__sanitizer_dtor_callback_vptr({{.*}}){{.*}}{{.*}}, !dbg ![[DI2:[0-9]+]]
// CHECK: ret void
// poison int and double
// CHECK-LABEL: define {{.*}}ZN4BaseD2Ev
-// CHECK: call void @__sanitizer_dtor_callback_fields({{.*}}, i64 16){{.*}}, !dbg ![[DI2:[0-9]+]]
-// CHECK: call void @__sanitizer_dtor_callback_vptr({{.*}}{{.*}}, !dbg ![[DI2]]
+// CHECK: call void @__sanitizer_dtor_callback_fields({{.*}}, i64 16){{.*}}, !dbg ![[DI3:[0-9]+]]
+// CHECK: call void @__sanitizer_dtor_callback_vptr({{.*}}{{.*}}, !dbg ![[DI4:[0-9]+]]
// CHECK: ret void
// poison int, ignore vector, poison int
// CHECK-LABEL: define {{.*}}ZN7DerivedD2Ev
-// CHECK: call void @__sanitizer_dtor_callback_fields({{.*}}, i64 4){{.*}}, !dbg ![[DI3:[0-9]+]]
+// CHECK: call void @__sanitizer_dtor_callback_fields({{.*}}, i64 4){{.*}}, !dbg ![[DI5:[0-9]+]]
// CHECK: call void {{.*}}ZN6VectorIiED1Ev
-// CHECK: call void @__sanitizer_dtor_callback_fields({{.*}}, i64 4){{.*}}, !dbg ![[DI3]]
+// CHECK: call void @__sanitizer_dtor_callback_fields({{.*}}, i64 4){{.*}}, !dbg ![[DI6:[0-9]+]]
// CHECK: call void {{.*}}ZN4BaseD2Ev
// CHECK: ret void
// poison int
// CHECK-LABEL: define {{.*}}ZN6VectorIiED2Ev
-// CHECK: call void @__sanitizer_dtor_callback_fields({{.*}}, i64 4){{.*}}, !dbg ![[DI5:[0-9]+]]
+// CHECK: call void @__sanitizer_dtor_callback_fields({{.*}}, i64 4){{.*}}, !dbg ![[DI7:[0-9]+]]
// CHECK: ret void
// CHECK-LABEL: !DIFile{{.*}}.cpp
// CHECK-DAG: ![[DI0]] = {{.*}}line: [[@LINE-49]]
-// CHECK-DAG: ![[DI1]] = {{.*}}line: [[@LINE-60]]
-// CHECK-DAG: ![[DI2]] = {{.*}}line: [[@LINE-71]]
-// CHECK-DAG: ![[DI3]] = {{.*}}line: [[@LINE-52]]
-// CHECK-DAG: ![[DI5]] = {{.*}}line: [[@LINE-83]]
+// CHECK-DAG: ![[DI1]] = {{.*}}line: [[@LINE-66]]
+// CHECK-DAG: ![[DI2]] = {{.*}}line: [[@LINE-61]]
+// CHECK-DAG: ![[DI3]] = {{.*}}line: [[@LINE-78]]
+// CHECK-DAG: ![[DI5]] = {{.*}}line: [[@LINE-57]]
+// CHECK-DAG: ![[DI6]] = {{.*}}line: [[@LINE-60]]
+// CHECK-DAG: ![[DI7]] = {{.*}}line: [[@LINE-88]]
diff --git a/clang/test/CodeGenCXX/sanitize-dtor-trivial-base.cpp b/clang/test/CodeGenCXX/sanitize-dtor-trivial-base.cpp
index cfb80f8dbd6c..07df5632c754 100644
--- a/clang/test/CodeGenCXX/sanitize-dtor-trivial-base.cpp
+++ b/clang/test/CodeGenCXX/sanitize-dtor-trivial-base.cpp
@@ -20,10 +20,11 @@ Derived d;
// Poison members, then poison the trivial base class.
// CHECK-LABEL: define {{.*}}DerivedD2Ev
// CHECK: %[[GEP:[0-9a-z]+]] = getelementptr i8, i8* {{.*}}, i64 16
-// CHECK: call void @__sanitizer_dtor_callback_fields({{.*}}%[[GEP]], i64 4{{.*}}, !dbg ![[DI:[0-9]+]]
-// CHECK: call void @__sanitizer_dtor_callback_fields({{.*}}, i64 16{{.*}}, !dbg ![[DI]]
+// CHECK: call void @__sanitizer_dtor_callback_fields({{.*}}%[[GEP]], i64 4{{.*}}, !dbg ![[DI1:[0-9]+]]
+// CHECK: call void @__sanitizer_dtor_callback_fields({{.*}}, i64 16{{.*}}, !dbg ![[DI2:[0-9]+]]
// CHECK: ret void
// CHECK-LABEL: !DIFile{{.*}}cpp
-// CHECK-DAG: ![[DI]] = {{.*}}line: [[@LINE-14]]
+// CHECK-DAG: ![[DI1]] = {{.*}}line: [[@LINE-16]]
+// CHECK-DAG: ![[DI2]] = {{.*}}line: [[@LINE-24]]
diff --git a/clang/test/CodeGenCXX/sanitize-dtor-trivial.cpp b/clang/test/CodeGenCXX/sanitize-dtor-trivial.cpp
index e2b19424542b..9b473b2e16f5 100644
--- a/clang/test/CodeGenCXX/sanitize-dtor-trivial.cpp
+++ b/clang/test/CodeGenCXX/sanitize-dtor-trivial.cpp
@@ -16,4 +16,4 @@ Trivial t;
// CHECK-LABEL: !DIFile{{.*}}.cpp
-// CHECK-DAG: ![[DI]] = {{.*}}line: [[@LINE-371]]
+// CHECK: ![[DI]] = {{.*}}line: [[@LINE-9]]
diff --git a/clang/test/CodeGenCXX/sanitize-dtor-vtable.cpp b/clang/test/CodeGenCXX/sanitize-dtor-vtable.cpp
index 49de930ce84a..71b5faae6abd 100644
--- a/clang/test/CodeGenCXX/sanitize-dtor-vtable.cpp
+++ b/clang/test/CodeGenCXX/sanitize-dtor-vtable.cpp
@@ -25,22 +25,23 @@ B b;
// CHECK-LABEL: define {{.*}}BD1Ev
// CHECK: call void {{.*}}BD2Ev
// CHECK: call void {{.*}}AD2Ev
-// CHECK: call void @__sanitizer_dtor_callback_vptr({{.*}}, !dbg ![[DI1:[0-9]+]]
+// CHECK: call void @__sanitizer_dtor_callback_vptr{{.*}}, !dbg ![[DI1:[0-9]+]]
// CHECK: ret void
// Since no virtual bases, poison vtable ptr here.
// CHECK-LABEL: define {{.*}}AD2Ev
-// CHECK: call void @__sanitizer_dtor_callback_fields({{.*}}, !dbg ![[DI2:[0-9]+]]
-// CHECK: call void @__sanitizer_dtor_callback_vptr({{.*}}, !dbg ![[DI2]]
+// CHECK: call void @__sanitizer_dtor_callback_fields{{.*}}, !dbg ![[DI2:[0-9]+]]
+// CHECK: call void @__sanitizer_dtor_callback_vptr{{.*}}, !dbg ![[DI3:[0-9]+]]
// CHECK: ret void
// Poison members
// CHECK-LABEL: define {{.*}}BD2Ev
-// CHECK: call void @__sanitizer_dtor_callback_fields({{.*}}, !dbg ![[DI4:[0-9]+]]
+// CHECK: call void @__sanitizer_dtor_callback_fields{{.*}}, !dbg ![[DI4:[0-9]+]]
// CHECK: ret void
-// CHECK-LABEL: !DIFile{{.*}}cpp
+// CHECK-LABEL: !DIFile{{.*}}sanitize-dtor-vtable.cpp
// CHECK-DAG: ![[DI1]] = {{.*}}line: [[@LINE-28]]
-// CHECK-DAG: ![[DI2]] = {{.*}}line: [[@LINE-37]]
-// CHECK-DAG: ![[DI4]] = {{.*}}line: [[@LINE-30]]
+// CHECK-DAG: ![[DI2]] = {{.*}}line: [[@LINE-39]]
+// CHECK-DAG: ![[DI3]] = {{.*}}line: [[@LINE-38]]
+// CHECK-DAG: ![[DI4]] = {{.*}}line: [[@LINE-33]]
diff --git a/compiler-rt/test/msan/dtor-base-access.cpp b/compiler-rt/test/msan/dtor-base-access.cpp
index e182af280150..16f7b89d56e0 100644
--- a/compiler-rt/test/msan/dtor-base-access.cpp
+++ b/compiler-rt/test/msan/dtor-base-access.cpp
@@ -68,17 +68,20 @@ int main() {
__msan_print_shadow(&g->tb0, sizeof(g->tb0));
// CHECK: Member fields were destroyed
// CHECK: {{#0 0x.* in __sanitizer_dtor_callback}}
- // CHECK: {{#1 0x.* in .*~Derived.*cpp:}}[[@LINE-20]]:
+ // CHECK: {{#1 0x.* in .*~Derived.*cpp:}}[[@LINE-56]]:
+ // CHECK: {{#2 0x.* in .*~Derived.*cpp:}}[[@LINE-21]]:
__msan_print_shadow(&g->b, sizeof(g->b));
// CHECK: Member fields were destroyed
// CHECK: {{#0 0x.* in __sanitizer_dtor_callback}}
- // CHECK: {{#1 0x.* in .*~Base.*cpp:}}[[@LINE-33]]:
+ // CHECK: {{#1 0x.* in .*~Base.*cpp:}}[[@LINE-67]]:
+ // CHECK: {{#2 0x.* in .*~Base.*cpp:}}[[@LINE-35]]:
__msan_print_shadow(&g->tb1, sizeof(g->tb1));
// CHECK: Member fields were destroyed
// CHECK: {{#0 0x.* in __sanitizer_dtor_callback}}
- // CHECK: {{#1 0x.* in .*~Derived.*cpp:}}[[@LINE-30]]:
+ // CHECK: {{#1 0x.* in .*~Derived.*cpp:}}[[@LINE-62]]:
+ // CHECK: {{#2 0x.* in .*~Derived.*cpp:}}[[@LINE-33]]:
return 0;
}
diff --git a/compiler-rt/test/msan/use-after-dtor.cpp b/compiler-rt/test/msan/use-after-dtor.cpp
index 385dc349f4d5..cbd6a1ce40e0 100644
--- a/compiler-rt/test/msan/use-after-dtor.cpp
+++ b/compiler-rt/test/msan/use-after-dtor.cpp
@@ -34,7 +34,8 @@ int main() {
// CHECK-ORIGINS: Member fields were destroyed
// CHECK-ORIGINS: {{#0 0x.* in __sanitizer_dtor_callback}}
- // CHECK-ORIGINS: {{#1 0x.* in .*~Simple.*cpp:}}[[@LINE-18]]:
+ // CHECK-ORIGINS: {{#1 0x.* in .*~Simple.*cpp:}}[[@LINE-24]]:
+ // CHECK-ORIGINS: {{#2 0x.* in .*~Simple.*cpp:}}[[@LINE-19]]:
// CHECK-UAD: SUMMARY: MemorySanitizer: use-of-uninitialized-value {{.*main}}
// CHECK-UAD-OFF-NOT: SUMMARY: MemorySanitizer: use-of-uninitialized-value
More information about the llvm-commits
mailing list