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

Paul Kirth via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Jan 11 16:20:44 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>


================
@@ -0,0 +1,58 @@
+// REQUIRES: linux
+// RUN: rm -rf %t
+// 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: llvm-symbolizer --filter-markup --debug-file-directory=%t < %t/sanitizer.out | FileCheck %s
+
+#include "test.h"
+
+int Global;
+
+[[gnu::noinline]] void foo1() { Global = 42; }
+
+[[gnu::noinline]] void bar1() {
+  volatile int tmp = 42;
+  int tmp2 = tmp;
+  (void)tmp2;
+  foo1();
+}
+
+[[gnu::noinline]] void foo2() {
+  volatile int tmp = Global;
+  int tmp2 = tmp;
+  (void)tmp2;
+}
+
+[[gnu::noinline]] void bar2() {
+  volatile int tmp = 42;
+  int tmp2 = tmp;
+  (void)tmp2;
+  foo2();
+}
+
+void *Thread1(void *x) {
+  barrier_wait(&barrier);
+  bar1();
+  return NULL;
+}
+
+int main() {
+  barrier_init(&barrier, 2);
+  pthread_t t;
+  pthread_create(&t, NULL, Thread1, NULL);
+  bar2();
+  barrier_wait(&barrier);
+  pthread_join(t, NULL);
+}
+
+//      CHECK: WARNING: ThreadSanitizer: data race
+//      CHECK:   Write of size 4 at {{.*}} by thread T1:
+//  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]]
----------------
ilovepi wrote:

There's more sophisticated users of FileCheck then me, but my rule of thumb is:

- If the ordering is fixed, but other elements that you will not try to match may occur, use CHECK.  (If its ambiguous, match some other property first)
- If the order not fixed for elements I need to match, use CHECK-DAG.
- If the order is completely fixed: use CHECK-NEXT after the initial match.

That's served me pretty well, but YMMV.

In this case, we can probably just use CHECK, if its possible other output will be interleaved, but the total order is fixed (which I think is this case)

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


More information about the llvm-branch-commits mailing list