1// Test line numbers in signal handlers
2// Fails with debug checks: https://bugs.llvm.org/show_bug.cgi?id=46860
3// XFAIL: !compiler-rt-optimized && tsan
4
5// RUN: %clangxx %s -o %t -O0
6// RUN: %env_tool_opts=handle_segv=1:print_stacktrace=1 not %run %t 1 2>&1 | FileCheck --check-prefixes=CHECK1,CHECK %s
7// RUN: %env_tool_opts=handle_segv=1:print_stacktrace=1 not %run %t 2 2>&1 | FileCheck --check-prefixes=CHECK2,CHECK %s
8
9#include <cstdio>
10#include <string>
11
12// CHECK: [[SAN:.*Sanitizer]]:DEADLYSIGNAL
13// CHECK: ERROR: [[SAN]]: SEGV on unknown address {{0x[^ ]*}} (pc
14int main(int argc, char **argv) {
15 int n = atoi(nptr: argv[1]);
16
17 if (n == 1)
18 *((volatile int *)0x0) = __LINE__;
19 // CHECK1: #{{[0-9]+ .*}}main {{.*}}signal_line.cpp:[[@LINE-1]]:[[TAB:[0-9]+]]
20 // CHECK1: SUMMARY: [[SAN]]: SEGV {{.*}}signal_line.cpp:[[@LINE-2]]:[[TAB]] in main
21
22 if (n == 2)
23 *((volatile int *)0x1) = __LINE__;
24 // CHECK2: #{{[0-9]+ .*}}main {{.*}}signal_line.cpp:[[@LINE-1]]:[[TAB:[0-9]+]]
25 // CHECK2: SUMMARY: [[SAN]]: SEGV {{.*}}signal_line.cpp:[[@LINE-2]]:[[TAB]] in main
26}
27

source code of compiler-rt/test/sanitizer_common/TestCases/Linux/signal_line.cpp