12d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines// RUN: %clangxx_asan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-%os --check-prefix=CHECK
22d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines// RUN: %clangxx_asan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-%os --check-prefix=CHECK
32d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines// RUN: %clangxx_asan -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-%os --check-prefix=CHECK
42d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines// RUN: %clangxx_asan -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-%os --check-prefix=CHECK
541f85b9e6a88f801955d99c8a8233b97e64c51ffAlexey Samsonov
641f85b9e6a88f801955d99c8a8233b97e64c51ffAlexey Samsonov__attribute__((noinline))
741f85b9e6a88f801955d99c8a8233b97e64c51ffAlexey Samsonovstatic void NullDeref(int *ptr) {
855425eb7ad3f18a1f740e0e445bc79a012429766Alexey Samsonov  // CHECK: ERROR: AddressSanitizer: SEGV on unknown address
92d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines  // CHECK:   {{0x0*000.. .*pc 0x.*}}
1055425eb7ad3f18a1f740e0e445bc79a012429766Alexey Samsonov  ptr[10]++;  // BOOM
1155425eb7ad3f18a1f740e0e445bc79a012429766Alexey Samsonov  // atos on Mac cannot extract the symbol name correctly.
1255425eb7ad3f18a1f740e0e445bc79a012429766Alexey Samsonov  // CHECK-Linux: {{    #0 0x.* in NullDeref.*null_deref.cc:}}[[@LINE-2]]
1355425eb7ad3f18a1f740e0e445bc79a012429766Alexey Samsonov  // CHECK-Darwin: {{    #0 0x.* in .*NullDeref.*null_deref.cc:}}[[@LINE-3]]
1441f85b9e6a88f801955d99c8a8233b97e64c51ffAlexey Samsonov}
1541f85b9e6a88f801955d99c8a8233b97e64c51ffAlexey Samsonovint main() {
1641f85b9e6a88f801955d99c8a8233b97e64c51ffAlexey Samsonov  NullDeref((int*)0);
17ed936c1d3a8db321b45d2e249159ec48c6450043Alexey Samsonov  // CHECK: {{    #1 0x.* in main.*null_deref.cc:}}[[@LINE-1]]
18d9def29fe0dc8fc70ef270dcc1a266ad9257ec1fAlexey Samsonov  // CHECK: {{AddressSanitizer can not provide additional info.}}
1941f85b9e6a88f801955d99c8a8233b97e64c51ffAlexey Samsonov}
20