Home | History | Annotate | Download | only in TypeCheck
      1 // RUN: %clang -fsanitize=null %s -O3 -o %t
      2 // RUN: %t l 2>&1 | FileCheck %s --check-prefix=CHECK-LOAD
      3 // RUN: %t s 2>&1 | FileCheck %s --check-prefix=CHECK-STORE
      4 // RUN: %t r 2>&1 | FileCheck %s --check-prefix=CHECK-REFERENCE
      5 // RUN: %t m 2>&1 | FileCheck %s --check-prefix=CHECK-MEMBER
      6 // RUN: %t f 2>&1 | FileCheck %s --check-prefix=CHECK-MEMFUN
      7 
      8 struct S {
      9   int f() { return 0; }
     10   int k;
     11 };
     12 
     13 int main(int, char **argv) {
     14   int *p = 0;
     15   S *s = 0;
     16 
     17   (void)*p; // ok!
     18 
     19   switch (argv[1][0]) {
     20   case 'l':
     21     // CHECK-LOAD: null.cpp:22:12: runtime error: load of null pointer of type 'int'
     22     return *p;
     23   case 's':
     24     // CHECK-STORE: null.cpp:25:5: runtime error: store to null pointer of type 'int'
     25     *p = 1;
     26     break;
     27   case 'r':
     28     // CHECK-REFERENCE: null.cpp:29:15: runtime error: reference binding to null pointer of type 'int'
     29     {int &r = *p;}
     30     break;
     31   case 'm':
     32     // CHECK-MEMBER: null.cpp:33:15: runtime error: member access within null pointer of type 'S'
     33     return s->k;
     34   case 'f':
     35     // CHECK-MEMFUN: null.cpp:36:12: runtime error: member call on null pointer of type 'S'
     36     return s->f();
     37   }
     38 }
     39