[test][msan] Add debug info use-after-dtor tests
authorVitaly Buka <vitalybuka@google.com>
Mon, 29 Aug 2022 06:05:23 +0000 (23:05 -0700)
committerVitaly Buka <vitalybuka@google.com>
Mon, 29 Aug 2022 06:05:23 +0000 (23:05 -0700)
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

index a685f2e..1e141d5 100644 (file)
@@ -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;
 }
index d8be877..7e50c49 100644 (file)
@@ -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
 }
index fbf33f0..67582c1 100644 (file)
@@ -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