blob: 66f778de8a3099c4bc64ddf3ef512a137524bf0e [file] [log] [blame]
Mikhail R. Gadelha8cd2ee12018-06-04 14:40:44 +00001// RUN: %clang_cc1 -analyze -analyzer-checker=core,unix.Malloc,debug.ExprInspection -DNO_CROSSCHECK -verify %s
2// RUN: %clang_cc1 -analyze -analyzer-checker=core,unix.Malloc,debug.ExprInspection -analyzer-config crosscheck-with-z3=true -verify %s
3// REQUIRES: z3
4
5int foo(int x)
6{
7 int *z = 0;
8 if ((x & 1) && ((x & 1) ^ 1))
9#ifdef NO_CROSSCHECK
10 return *z; // expected-warning {{Dereference of null pointer (loaded from variable 'z')}}
11#else
12 return *z; // no-warning
13#endif
14 return 0;
15}
16
17void g(int d);
18
19void f(int *a, int *b) {
20 int c = 5;
21 if ((a - b) == 0)
22 c = 0;
23 if (a != b)
24#ifdef NO_CROSSCHECK
25 g(3 / c); // expected-warning {{Division by zero}}
26#else
27 g(3 / c); // no-warning
28#endif
29}
30
31_Bool nondet_bool();
32
33void h(int d) {
34 int x, y, k, z = 1;
35#ifdef NO_CROSSCHECK
36 while (z < k) { // expected-warning {{The right operand of '<' is a garbage value}}
37#else
38 while (z < k) { // expected-warning {{The right operand of '<' is a garbage value}}
39#endif
40 z = 2 * z;
41 }
42}
43
44void i() {
45 _Bool c = nondet_bool();
46 if (c) {
47 h(1);
48 } else {
49 h(2);
50 }
51}