xref: /aosp_15_r20/external/compiler-rt/test/asan/TestCases/null_deref.cc (revision 7c3d14c8b49c529e04be81a3ce6f5cc23712e4c6)
1*7c3d14c8STreehugger Robot // RUN: %clangxx_asan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s
2*7c3d14c8STreehugger Robot // RUN: %clangxx_asan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
3*7c3d14c8STreehugger Robot // RUN: %clangxx_asan -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s
4*7c3d14c8STreehugger Robot // RUN: %clangxx_asan -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s
5*7c3d14c8STreehugger Robot 
6*7c3d14c8STreehugger Robot __attribute__((noinline))
7*7c3d14c8STreehugger Robot // FIXME: Static symbols don't show up in PDBs. We can remove this once we start
8*7c3d14c8STreehugger Robot // using DWARF.
9*7c3d14c8STreehugger Robot #ifndef _MSC_VER
10*7c3d14c8STreehugger Robot static
11*7c3d14c8STreehugger Robot #endif
NullDeref(int * ptr)12*7c3d14c8STreehugger Robot void NullDeref(int *ptr) {
13*7c3d14c8STreehugger Robot   // CHECK: ERROR: AddressSanitizer: {{SEGV|access-violation}} on unknown address
14*7c3d14c8STreehugger Robot   // CHECK:   {{0x0*000.. .*pc 0x.*}}
15*7c3d14c8STreehugger Robot   ptr[10]++;  // BOOM
16*7c3d14c8STreehugger Robot   // atos on Mac cannot extract the symbol name correctly. Also, on FreeBSD 9.2
17*7c3d14c8STreehugger Robot   // the demangling function rejects local names with 'L' in front of them.
18*7c3d14c8STreehugger Robot   // CHECK: {{    #0 0x.* in .*NullDeref.*null_deref.cc:}}[[@LINE-3]]
19*7c3d14c8STreehugger Robot }
main()20*7c3d14c8STreehugger Robot int main() {
21*7c3d14c8STreehugger Robot   NullDeref((int*)0);
22*7c3d14c8STreehugger Robot   // CHECK: {{    #1 0x.* in main.*null_deref.cc:}}[[@LINE-1]]
23*7c3d14c8STreehugger Robot   // CHECK: AddressSanitizer can not provide additional info.
24*7c3d14c8STreehugger Robot }
25