[llvm-branch-commits] [llvm] [clang] [clang-tools-extra] [compiler-rt] [sanitizer_symbolizer] Add end to end test for symbolizer markup. (PR #77702)

Andres Villegas via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Jan 11 14:08:10 PST 2024


=?utf-8?q?Andrés?= Villegas <andresvi at google.com>,
=?utf-8?q?Andrés?= Villegas <andresvi at google.com>,
=?utf-8?q?Andrés?= Villegas <andresvi at google.com>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/77702 at github.com>


https://github.com/avillega updated https://github.com/llvm/llvm-project/pull/77702

>From a3220262a3236115d55235e4cc34acc8202268f4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A9s=20Villegas?= <andresvi at google.com>
Date: Wed, 10 Jan 2024 23:56:45 +0000
Subject: [PATCH 1/4] Fix typo.

Created using spr 1.3.5
---
 .../test/asan/TestCases/use-after-free-symbolizer-markup.cpp    | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/compiler-rt/test/asan/TestCases/use-after-free-symbolizer-markup.cpp b/compiler-rt/test/asan/TestCases/use-after-free-symbolizer-markup.cpp
index 548ae57b5c3797..323de4ec7a36ed 100644
--- a/compiler-rt/test/asan/TestCases/use-after-free-symbolizer-markup.cpp
+++ b/compiler-rt/test/asan/TestCases/use-after-free-symbolizer-markup.cpp
@@ -1,5 +1,5 @@
 // COM: End to end test for the sanitizer symbolizer markup. Since it uses debug info
-// COM: to do offline symbolization we only check that the current module correctly is correctly symbolized  
+// COM: to do offline symbolization we only check that the current module is correctly symbolized  
 // REQUIRES: linux
 // RUN: %clangxx_asan %s -Wl,--build-id=0x12345678 -o %t.main
 // RUN: mkdir -p %t/.build-id/12

>From 29abe012394c582239b257a6a51b833b974743f1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A9s=20Villegas?= <andresvi at google.com>
Date: Thu, 11 Jan 2024 17:25:29 +0000
Subject: [PATCH 2/4] run git clang-format

Created using spr 1.3.5
---
 .../asan/TestCases/use-after-free-symbolizer-markup.cpp  | 9 ++++-----
 compiler-rt/test/tsan/simple_stack_symbolizer_markup.cpp | 6 ++----
 2 files changed, 6 insertions(+), 9 deletions(-)

diff --git a/compiler-rt/test/asan/TestCases/use-after-free-symbolizer-markup.cpp b/compiler-rt/test/asan/TestCases/use-after-free-symbolizer-markup.cpp
index 323de4ec7a36ed..8d818217eb5b63 100644
--- a/compiler-rt/test/asan/TestCases/use-after-free-symbolizer-markup.cpp
+++ b/compiler-rt/test/asan/TestCases/use-after-free-symbolizer-markup.cpp
@@ -1,5 +1,5 @@
 // COM: End to end test for the sanitizer symbolizer markup. Since it uses debug info
-// COM: to do offline symbolization we only check that the current module is correctly symbolized  
+// COM: to do offline symbolization we only check that the current module is correctly symbolized
 // REQUIRES: linux
 // RUN: %clangxx_asan %s -Wl,--build-id=0x12345678 -o %t.main
 // RUN: mkdir -p %t/.build-id/12
@@ -9,9 +9,8 @@
 
 #include <stdlib.h>
 
-[[gnu::noinline]]
-char *alloc() {
-  char *x = (char*)malloc(10 * sizeof(char));
+[[gnu::noinline]] char *alloc() {
+  char *x = (char *)malloc(10 * sizeof(char));
   return x;
 }
 int main() {
@@ -26,7 +25,7 @@ int main() {
 // CHECK: {{0x.* is located 5 bytes inside of 10-byte region .0x.*,0x.*}}
 // CHECK: {{freed by thread T0 here:}}
 // CHECK: {{    #1 0x.* main .*use-after-free-symbolizer-markup.cpp:}}[[@LINE-9]]
-// CHECK: {{previously allocated by thread T0 here:}} 
+// CHECK: {{previously allocated by thread T0 here:}}
 // CHECK: {{    #1 0x.* alloc\(\) .*use-after-free-symbolizer-markup.cpp:}}[[@LINE-16]]
 // CHECK: {{    #2 0x.* main .*use-after-free-symbolizer-markup.cpp:}}[[@LINE-13]]
 // CHECK: Shadow byte legend (one shadow byte represents {{[0-9]+}} application bytes):
diff --git a/compiler-rt/test/tsan/simple_stack_symbolizer_markup.cpp b/compiler-rt/test/tsan/simple_stack_symbolizer_markup.cpp
index 5798986d73839e..a4f5e0e9d9fe46 100644
--- a/compiler-rt/test/tsan/simple_stack_symbolizer_markup.cpp
+++ b/compiler-rt/test/tsan/simple_stack_symbolizer_markup.cpp
@@ -1,5 +1,5 @@
 // REQUIRES: linux
-// RUN: %clangxx_tsan %s -Wl,--build-id=0x12345678 -O1 -o %t.main 
+// RUN: %clangxx_tsan %s -Wl,--build-id=0x12345678 -O1 -o %t.main
 // RUN: mkdir -p %t/.build-id/12
 // RUN: cp %t.main %t/.build-id/12/345678.debug
 // RUN: %env_tsan_opts=enable_symbolizer_markup=1 %deflake %run %t.main >%t/sanitizer.out
@@ -9,9 +9,7 @@
 
 int Global;
 
-void __attribute__((noinline)) foo1() {
-  Global = 42;
-}
+void __attribute__((noinline)) foo1() { Global = 42; }
 
 void __attribute__((noinline)) bar1() {
   volatile int tmp = 42;

>From 2f11f65aadc8411c544f60bd3af29529625bc177 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A9s=20Villegas?= <andresvi at google.com>
Date: Thu, 11 Jan 2024 20:21:04 +0000
Subject: [PATCH 3/4] Fix review comments

Created using spr 1.3.5
---
 .../use-after-free-symbolizer-markup.cpp      | 32 ++++++++++---------
 .../tsan/simple_stack_symbolizer_markup.cpp   | 29 +++++++++--------
 2 files changed, 32 insertions(+), 29 deletions(-)

diff --git a/compiler-rt/test/asan/TestCases/use-after-free-symbolizer-markup.cpp b/compiler-rt/test/asan/TestCases/use-after-free-symbolizer-markup.cpp
index 8d818217eb5b63..2da07892daf6c5 100644
--- a/compiler-rt/test/asan/TestCases/use-after-free-symbolizer-markup.cpp
+++ b/compiler-rt/test/asan/TestCases/use-after-free-symbolizer-markup.cpp
@@ -1,10 +1,12 @@
-// COM: End to end test for the sanitizer symbolizer markup. Since it uses debug info
-// COM: to do offline symbolization we only check that the current module is correctly symbolized
+/// End to end test for the sanitizer symbolizer markup.
+/// Since it uses debug info to do offline symbolization we only check that the
+/// current module is correctly symbolized.
 // REQUIRES: linux
-// RUN: %clangxx_asan %s -Wl,--build-id=0x12345678 -o %t.main
+// RUN: rm -rf %t
 // RUN: mkdir -p %t/.build-id/12
-// RUN: cp %t.main %t/.build-id/12/345678.debug
-// RUN: %env_asan_opts=enable_symbolizer_markup=1 not %run %t.main 2>%t/sanitizer.out
+// RUN: %clangxx_asan %s -Wl,--build-id=0x12345678 -o %t/main
+// RUN: cp %t/main %t/.build-id/12/345678.debug
+// RUN: %env_asan_opts=enable_symbolizer_markup=1 not %run %t/main 2>%t/sanitizer.out
 // RUN: llvm-symbolizer --filter-markup --debug-file-directory=%t < %t/sanitizer.out | FileCheck %s
 
 #include <stdlib.h>
@@ -18,16 +20,16 @@ int main() {
   free(x);
   return x[5];
 }
-// CHECK: {{.*ERROR: AddressSanitizer: heap-use-after-free on address}}
-// CHECK: {{0x.* at pc 0x.* bp 0x.* sp 0x.*}}
-// CHECK: {{READ of size 1 at 0x.* thread T0}}
-// CHECK: {{    #0 0x.* main .*use-after-free-symbolizer-markup.cpp:}}[[@LINE-5]]
-// CHECK: {{0x.* is located 5 bytes inside of 10-byte region .0x.*,0x.*}}
-// CHECK: {{freed by thread T0 here:}}
-// CHECK: {{    #1 0x.* main .*use-after-free-symbolizer-markup.cpp:}}[[@LINE-9]]
-// CHECK: {{previously allocated by thread T0 here:}}
-// CHECK: {{    #1 0x.* alloc\(\) .*use-after-free-symbolizer-markup.cpp:}}[[@LINE-16]]
-// CHECK: {{    #2 0x.* main .*use-after-free-symbolizer-markup.cpp:}}[[@LINE-13]]
+// CHECK: ERROR: AddressSanitizer: heap-use-after-free on address
+// CHECK: {{0x.*}} at pc {{0x.*}} bp {{0x.*}} sp {{0x.*}}
+// CHECK: READ of size 1 at {{0x.*}} thread T0
+// CHECK:   #0 {{0x.*}} main{{.*}} {{.*}}use-after-free-symbolizer-markup.cpp:[[#@LINE - 5]]
+// CHECK: {{0x.*}} is located 5 bytes inside of 10-byte region {{.0x.*,0x.*}}
+// CHECK: freed by thread T0 here:
+// CHECK:   #1 {{0x.*}} main{{.*}} {{.*}}use-after-free-symbolizer-markup.cpp:[[#@LINE - 9]]
+// CHECK: previously allocated by thread T0 here:
+// CHECK:   #1 {{0x.*}} alloc{{.*}} {{.*}}use-after-free-symbolizer-markup.cpp:[[#@LINE - 16]]
+// CHECK:   #2 {{0x.*}} main{{.*}} {{.*}}use-after-free-symbolizer-markup.cpp:[[#@LINE - 13]]
 // CHECK: Shadow byte legend (one shadow byte represents {{[0-9]+}} application bytes):
 // CHECK: Global redzone:
 // CHECK: ASan internal:
diff --git a/compiler-rt/test/tsan/simple_stack_symbolizer_markup.cpp b/compiler-rt/test/tsan/simple_stack_symbolizer_markup.cpp
index a4f5e0e9d9fe46..b51705696dbcb9 100644
--- a/compiler-rt/test/tsan/simple_stack_symbolizer_markup.cpp
+++ b/compiler-rt/test/tsan/simple_stack_symbolizer_markup.cpp
@@ -1,30 +1,31 @@
 // REQUIRES: linux
-// RUN: %clangxx_tsan %s -Wl,--build-id=0x12345678 -O1 -o %t.main
+// RUN: rm -rf %t
 // RUN: mkdir -p %t/.build-id/12
-// RUN: cp %t.main %t/.build-id/12/345678.debug
+// RUN: %clangxx_tsan %s -Wl,--build-id=0x12345678 -O1 -o %t/main
+// RUN: cp %t/main %t/.build-id/12/345678.debug
 // RUN: %env_tsan_opts=enable_symbolizer_markup=1 %deflake %run %t.main >%t/sanitizer.out
-// RUN: llvm-symbolizer --filter-markup --debug-file-directory=%t < %t/sanitizer.out | FileCheck %s --dump-input=always
+// RUN: llvm-symbolizer --filter-markup --debug-file-directory=%t < %t/sanitizer.out | FileCheck %s
 
 #include "test.h"
 
 int Global;
 
-void __attribute__((noinline)) foo1() { Global = 42; }
+[[gnu::noinline]] void foo1() { Global = 42; }
 
-void __attribute__((noinline)) bar1() {
+[[gnu::noinline]] void bar1() {
   volatile int tmp = 42;
   int tmp2 = tmp;
   (void)tmp2;
   foo1();
 }
 
-void __attribute__((noinline)) foo2() {
+[[gnu::noinline]] void foo2() {
   volatile int tmp = Global;
   int tmp2 = tmp;
   (void)tmp2;
 }
 
-void __attribute__((noinline)) bar2() {
+[[gnu::noinline]] void bar2() {
   volatile int tmp = 42;
   int tmp2 = tmp;
   (void)tmp2;
@@ -48,10 +49,10 @@ int main() {
 
 //      CHECK: WARNING: ThreadSanitizer: data race
 //      CHECK:   Write of size 4 at {{.*}} by thread T1:
-//      CHECK:     #0 {{0x.*}} foo1{{.*}} {{.*}}simple_stack_symbolizer_markup.cpp:[[@LINE-40]]
-// CHECK-NEXT:     #1 {{0x.*}} bar1{{.*}} {{.*}}simple_stack_symbolizer_markup.cpp:[[@LINE-34]]
-// CHECK-NEXT:     #2 {{0x.*}} Thread1{{.*}} {{.*}}simple_stack_symbolizer_markup.cpp:[[@LINE-17]]
-//      CHECK:   Previous read of size 4 at {{.*}} by main thread:
-//      CHECK:     #0 {{0x.*}} foo2{{.*}} {{.*}}simple_stack_symbolizer_markup.cpp:[[@LINE-33]]
-// CHECK-NEXT:     #1 {{0x.*}} bar2{{.*}} {{.*}}simple_stack_symbolizer_markup.cpp:[[@LINE-25]]
-// CHECK-NEXT:     #2 {{0x.*}} main{{.*}} {{.*}}simple_stack_symbolizer_markup.cpp:[[@LINE-13]]
+//  CHECK-DAG:     #0 {{0x.*}} foo1{{.*}} {{.*}}simple_stack_symbolizer_markup.cpp:[[#@LINE - 39]]
+// CHECK-NEXT:     #1 {{0x.*}} bar1{{.*}} {{.*}}simple_stack_symbolizer_markup.cpp:[[#@LINE - 34]]
+// CHECK-NEXT:     #2 {{0x.*}} Thread1{{.*}} {{.*}}simple_stack_symbolizer_markup.cpp:[[#@LINE - 17]]
+//  CHECK-DAG:   Previous read of size 4 at {{.*}} by main thread:
+//  CHECK-DAG:     #0 {{0x.*}} foo2{{.*}} {{.*}}simple_stack_symbolizer_markup.cpp:[[#@LINE - 33]]
+// CHECK-NEXT:     #1 {{0x.*}} bar2{{.*}} {{.*}}simple_stack_symbolizer_markup.cpp:[[#@LINE - 25]]
+// CHECK-NEXT:     #2 {{0x.*}} main{{.*}} {{.*}}simple_stack_symbolizer_markup.cpp:[[#@LINE - 13]]

>From 453ce996d9789660ac28e72d510de820ff716cb1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A9s=20Villegas?= <andresvi at google.com>
Date: Thu, 11 Jan 2024 22:07:57 +0000
Subject: [PATCH 4/4] Fix runnable name

Created using spr 1.3.5
---
 compiler-rt/test/tsan/simple_stack_symbolizer_markup.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/compiler-rt/test/tsan/simple_stack_symbolizer_markup.cpp b/compiler-rt/test/tsan/simple_stack_symbolizer_markup.cpp
index b51705696dbcb9..564650c6f2ec6f 100644
--- a/compiler-rt/test/tsan/simple_stack_symbolizer_markup.cpp
+++ b/compiler-rt/test/tsan/simple_stack_symbolizer_markup.cpp
@@ -3,7 +3,7 @@
 // RUN: mkdir -p %t/.build-id/12
 // RUN: %clangxx_tsan %s -Wl,--build-id=0x12345678 -O1 -o %t/main
 // RUN: cp %t/main %t/.build-id/12/345678.debug
-// RUN: %env_tsan_opts=enable_symbolizer_markup=1 %deflake %run %t.main >%t/sanitizer.out
+// RUN: %env_tsan_opts=enable_symbolizer_markup=1 %deflake %run %t/main >%t/sanitizer.out
 // RUN: llvm-symbolizer --filter-markup --debug-file-directory=%t < %t/sanitizer.out | FileCheck %s
 
 #include "test.h"



More information about the llvm-branch-commits mailing list