[compiler-rt] 64dbcca - [test][msan] Add debug info use-after-dtor tests

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Sun Aug 28 23:06:29 PDT 2022


Author: Vitaly Buka
Date: 2022-08-28T23:05:23-07:00
New Revision: 64dbcca6cf022753795e57e6b01dfc9fdf1b66a6

URL: https://github.com/llvm/llvm-project/commit/64dbcca6cf022753795e57e6b01dfc9fdf1b66a6
DIFF: https://github.com/llvm/llvm-project/commit/64dbcca6cf022753795e57e6b01dfc9fdf1b66a6.diff

LOG: [test][msan] Add debug info use-after-dtor tests

Added: 
    

Modified: 
    compiler-rt/test/msan/dtor-base-access.cpp
    compiler-rt/test/msan/dtor-vtable-multiple-inheritance.cpp
    compiler-rt/test/msan/use-after-dtor.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/test/msan/dtor-base-access.cpp b/compiler-rt/test/msan/dtor-base-access.cpp
index a685f2e8b21d6..1e141d5afdb26 100644
--- a/compiler-rt/test/msan/dtor-base-access.cpp
+++ b/compiler-rt/test/msan/dtor-base-access.cpp
@@ -1,8 +1,6 @@
-// RUN: %clangxx_msan %s -O0 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && %run %t >%t.out 2>&1
-
-// RUN: %clangxx_msan %s -O1 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && %run %t >%t.out 2>&1
-
-// RUN: %clangxx_msan %s -O2 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && %run %t >%t.out 2>&1
+// RUN: %clangxx_msan %s -O0 -fsanitize-memory-use-after-dtor -fsanitize-memory-track-origins -o %t && %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_msan %s -O1 -fsanitize-memory-use-after-dtor -fsanitize-memory-track-origins -o %t && %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_msan %s -O2 -fsanitize-memory-use-after-dtor -fsanitize-memory-track-origins -o %t && %run %t 2>&1 | FileCheck %s
 
 #include <sanitizer/msan_interface.h>
 #include <assert.h>
@@ -66,5 +64,21 @@ int main() {
   assert(__msan_test_shadow(&g->b, sizeof(g->b)) == 0);
   assert(__msan_test_shadow(&g->tb1, sizeof(g->tb1)) == 0);
   assert(__msan_test_shadow(&g->d, sizeof(g->d)) == 0);
+
+  __msan_print_shadow(&g->tb0, sizeof(g->tb0));
+  // CHECK: Memory was marked as uninitialized
+  // CHECK: {{#0 0x.* in __sanitizer_dtor_callback}}
+  // CHECK: {{#1 0x.* in .*~Derived.*cpp:}}[[@LINE-20]]:
+
+  __msan_print_shadow(&g->b, sizeof(g->b));
+  // CHECK: Memory was marked as uninitialized
+  // CHECK: {{#0 0x.* in __sanitizer_dtor_callback}}
+  // CHECK: {{#1 0x.* in .*~Base.*cpp:}}[[@LINE-33]]:
+
+  __msan_print_shadow(&g->tb1, sizeof(g->tb1));
+  // CHECK: Memory was marked as uninitialized
+  // CHECK: {{#0 0x.* in __sanitizer_dtor_callback}}
+  // CHECK: {{#1 0x.* in .*~Derived.*cpp:}}[[@LINE-30]]:
+
   return 0;
 }

diff  --git a/compiler-rt/test/msan/dtor-vtable-multiple-inheritance.cpp b/compiler-rt/test/msan/dtor-vtable-multiple-inheritance.cpp
index d8be877fb9705..7e50c49928e6a 100644
--- a/compiler-rt/test/msan/dtor-vtable-multiple-inheritance.cpp
+++ b/compiler-rt/test/msan/dtor-vtable-multiple-inheritance.cpp
@@ -1,14 +1,9 @@
-// RUN: %clangxx_msan %s -O0 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && %run %t
-
-// RUN: %clangxx_msan %s -O1 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && %run %t
-
-// RUN: %clangxx_msan %s -O2 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && %run %t
-
-// RUN: %clangxx_msan %s -DCVPTR=1 -O2 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && not %run %t
-
-// RUN: %clangxx_msan %s -DEAVPTR=1 -O2 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && not %run %t
-
-// RUN: %clangxx_msan %s -DEDVPTR=1 -O2 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && not %run %t
+// RUN: %clangxx_msan %s -O0 -fsanitize-memory-use-after-dtor -o %t && %run %t
+// RUN: %clangxx_msan %s -O1 -fsanitize-memory-use-after-dtor -o %t && %run %t
+// RUN: %clangxx_msan %s -O2 -fsanitize-memory-use-after-dtor -o %t && %run %t
+// RUN: %clangxx_msan %s -DCVPTR=1 -O2 -fsanitize-memory-use-after-dtor -fsanitize-memory-track-origins -o %t && not %run %t 2>&1 | FileCheck %s --check-prefixes=CVPTR
+// RUN: %clangxx_msan %s -DEAVPTR=1 -O2 -fsanitize-memory-use-after-dtor -fsanitize-memory-track-origins -o %t && not %run %t 2>&1 | FileCheck %s --check-prefixes=EAVPTR
+// RUN: %clangxx_msan %s -DEDVPTR=1 -O2 -fsanitize-memory-use-after-dtor -fsanitize-memory-track-origins -o %t && not %run %t 2>&1 | FileCheck %s --check-prefixes=EDVPTR
 
 // Expected to quit due to invalid access when invoking
 // function using vtable.
@@ -32,8 +27,7 @@ class B : public virtual A {
 
 class C : public B {
  public:
-  int z;
-  ~C() {}
+   int z;
 };
 
 class D {
@@ -57,6 +51,10 @@ int main() {
   // This fails
 #ifdef CVPTR
   c->A_Foo();
+// CVPTR: Memory was marked as uninitialized
+// CVPTR: {{#0 0x.* in __sanitizer_dtor_callback}}
+// CVPTR: {{#1 0x.* in ~C .*cpp:}}[[@LINE-28]]:
+// CVPTR: {{#2 0x.* in main .*cpp:}}[[@LINE-7]]:
 #endif
 
   // Multiple inheritance, so has multiple vtables
@@ -65,8 +63,17 @@ int main() {
   // Both of these fail
 #ifdef EAVPTR
   e->A_Foo();
+// EAVPTR: Memory was marked as uninitialized
+// EAVPTR: {{#0 0x.* in __sanitizer_dtor_callback}}
+// EAVPTR: {{#1 0x.* in ~E .*cpp:}}[[@LINE-25]]:
+// EAVPTR: {{#2 0x.* in main .*cpp:}}[[@LINE-7]]:
 #endif
+
 #ifdef EDVPTR
   e->D_Foo();
+// EDVPTR: Memory was marked as uninitialized
+// EDVPTR: {{#0 0x.* in __sanitizer_dtor_callback}}
+// EDVPTR: {{#1 0x.* in ~E .*cpp:}}[[@LINE-33]]:
+// EDVPTR: {{#2 0x.* in main .*cpp:}}[[@LINE-15]]:
 #endif
 }

diff  --git a/compiler-rt/test/msan/use-after-dtor.cpp b/compiler-rt/test/msan/use-after-dtor.cpp
index fbf33f0dfbaaf..67582c18bc931 100644
--- a/compiler-rt/test/msan/use-after-dtor.cpp
+++ b/compiler-rt/test/msan/use-after-dtor.cpp
@@ -1,17 +1,8 @@
-// RUN: %clangxx_msan %s -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && not %run %t >%t.out 2>&1
-// RUN: FileCheck %s --check-prefix=CHECK-UAD < %t.out
-
-// RUN: %clangxx_msan %s -O1 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && not %run %t >%t.out 2>&1
-// RUN: FileCheck %s --check-prefix=CHECK-UAD < %t.out
-
-// RUN: %clangxx_msan %s -O2 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && not %run %t >%t.out 2>&1
-// RUN: FileCheck %s --check-prefix=CHECK-UAD < %t.out
-
-// RUN: %clangxx_msan %s -O1 -fsanitize=memory -fsanitize-memory-use-after-dtor -fsanitize-memory-track-origins -o %t && not %run %t >%t.out 2>&1
-// RUN: FileCheck %s --check-prefixes=CHECK-UAD,CHECK-ORIGINS < %t.out
-
-// RUN: %clangxx_msan %s -fno-sanitize-memory-use-after-dtor -o %t && not %run %t > %t.out 2>&1
-// RUN: FileCheck %s --check-prefix=CHECK-UAD-OFF < %t.out
+// RUN: %clangxx_msan %s -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-UAD
+// RUN: %clangxx_msan %s -O1 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && not %t 2>&1 | FileCheck %s --check-prefix=CHECK-UAD
+// RUN: %clangxx_msan %s -O2 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-UAD
+// RUN: %clangxx_msan %s -O1 -fsanitize=memory -fsanitize-memory-use-after-dtor -fsanitize-memory-track-origins -o %t && not %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK-UAD,CHECK-ORIGINS
+// RUN: %clangxx_msan %s -fno-sanitize-memory-use-after-dtor -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-UAD-OFF
 
 #include <sanitizer/msan_interface.h>
 #include <assert.h>
@@ -43,7 +34,7 @@ int main() {
 
   // CHECK-ORIGINS: Memory was marked as uninitialized
   // CHECK-ORIGINS: {{#0 0x.* in __sanitizer_dtor_callback}}
-  // CHECK-ORIGINS: {{#1 0x.* in .*~Simple}}
+  // CHECK-ORIGINS: {{#1 0x.* in .*~Simple.*cpp:}}[[@LINE-18]]:
 
   // 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