Home | History | Annotate | Download | only in inlining
      1 // RUN: %clang_cc1 -analyze -analyzer-checker=core -analyzer-config suppress-inlined-defensive-checks=true -verify %s
      2 
      3 // Perform inline defensive checks.
      4 void idc(int *p) {
      5 	if (p)
      6 		;
      7 }
      8 
      9 int test01(int *p) {
     10   if (p)
     11     ;
     12   return *p; // expected-warning {{Dereference of null pointer}}
     13 }
     14 
     15 int test02(int *p, int *x) {
     16   if (p)
     17     ;
     18   idc(p);
     19 	if (x)
     20 		;
     21   return *p; // expected-warning {{Dereference of null pointer}}
     22 }
     23 
     24 int test03(int *p, int *x) {
     25 	idc(p);
     26 	if (p)
     27 		;
     28 	return *p; // False negative
     29 }
     30 
     31 int deref04(int *p) {
     32   return *p; // expected-warning {{Dereference of null pointer}}
     33 }
     34 
     35 int test04(int *p) {
     36   if (p)
     37     ;
     38   idc(p);
     39   return deref04(p);
     40 }
     41 
     42 int test11(int *q, int *x) {
     43 	int *p = q;
     44 	if (q)
     45 		;
     46 	if (x)
     47 		;
     48 	return *p; // expected-warning{{Dereference of null pointer}}
     49 }
     50 
     51 int test12(int *q) {
     52 	int *p = q;
     53 	idc(q);
     54 	return *p;
     55 }
     56 
     57 int test13(int *q) {
     58 	int *p = q;
     59 	idc(p);
     60 	return *p;
     61 }
     62 
     63 int test21(int *q, int *x) {
     64 	if (q)
     65 		;
     66 	if (x)
     67 		;
     68 	int *p = q;
     69 	return *p; // expected-warning{{Dereference of null pointer}}
     70 }
     71 
     72 int test22(int *q, int *x) {
     73   idc(q);
     74 	if (x)
     75 		;
     76 	int *p = q;
     77 	return *p;
     78 }
     79 
     80 int test23(int *q, int *x) {
     81   idc(q);
     82 	if (x)
     83 		;
     84 	int *p = q;
     85   if (!p)
     86     ;
     87 	return *p; // False negative
     88 }
     89 
     90 void use(char *p) {
     91   if (!p)
     92     return;
     93   p[0] = 'a';
     94 }
     95 
     96 void test24(char *buffer) {
     97   use(buffer);
     98   buffer[1] = 'b';
     99 }
    100