• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // RUN: %clang_analyze_cc1 -w -analyzer-checker=core,debug.ExprInspection\
2 // RUN:                    -analyzer-config eagerly-assume=false -verify %s
3 
4 void clang_analyzer_eval(int);
5 
testAnd(int i,int * p)6 void testAnd(int i, int *p) {
7   int *nullP = 0;
8   int *knownP = &i;
9   clang_analyzer_eval((knownP && knownP) == 1); // expected-warning{{TRUE}}
10   clang_analyzer_eval((knownP && nullP) == 0); // expected-warning{{TRUE}}
11   clang_analyzer_eval((knownP && p) == 1); // expected-warning{{UNKNOWN}}
12 }
13 
testOr(int i,int * p)14 void testOr(int i, int *p) {
15   int *nullP = 0;
16   int *knownP = &i;
17   clang_analyzer_eval((nullP || knownP) == 1); // expected-warning{{TRUE}}
18   clang_analyzer_eval((nullP || nullP) == 0); // expected-warning{{TRUE}}
19   clang_analyzer_eval((nullP || p) == 1); // expected-warning{{UNKNOWN}}
20 }
21 
22 
23 // PR13461
testTypeIsInt(int i,void * p)24 int testTypeIsInt(int i, void *p) {
25   if (i | (p && p))
26     return 1;
27   return 0;
28 }
29 
30 // These crashed the analyzer at some point.
between(char * x)31 int between(char *x) {
32   extern char start[];
33   extern char end[];
34   return x >= start && x < end;
35 }
36 
undef(void)37 int undef(void) {}
useUndef(void)38 void useUndef(void) { 0 || undef(); }
39 
testPointer(void)40 void testPointer(void) { (void) (1 && testPointer && 0); }
41 
42 char *global_ap, *global_bp, *global_cp;
ambiguous_backtrack_1()43 void ambiguous_backtrack_1() {
44   for (;;) {
45     (global_bp - global_ap ? global_cp[global_bp - global_ap] : 0) || 1;
46     global_bp++;
47   }
48 }
49 
50 int global_a, global_b;
ambiguous_backtrack_2(int x)51 void ambiguous_backtrack_2(int x) {
52   global_a = x >= 2 ? 1 : x;
53   global_b == x && 9 || 2;
54 }
55