1 // RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -analyzer-checker=core,debug.ExprInspection %s -std=c++11 -verify
3 void clang_analyzer_eval(bool);
4 void clang_analyzer_warnIfReached();
6 void testAddressof(int x
) {
7 clang_analyzer_eval(&x
== __builtin_addressof(x
)); // expected-warning{{TRUE}}
16 clang_analyzer_eval(__builtin_object_size(&object
.y
, 0) == sizeof(object
) - sizeof(int)); // expected-warning{{TRUE}}
18 // Clang can't actually evaluate these builtin "calls", but importantly they don't actually evaluate the argument expression either.
21 clang_analyzer_eval(__builtin_object_size(&buf
[i
++], 0) == sizeof(buf
)); // expected-warning{{FALSE}}
22 clang_analyzer_eval(__builtin_object_size(&buf
[++i
], 0) == sizeof(buf
) - 1); // expected-warning{{FALSE}}
24 clang_analyzer_eval(i
== 0); // expected-warning{{TRUE}}
27 void test_assume_aligned_1(char *p
) {
30 q
= (char*) __builtin_assume_aligned(p
, 16);
31 clang_analyzer_eval(p
== q
); // expected-warning{{TRUE}}
34 void test_assume_aligned_2(char *p
) {
37 q
= (char*) __builtin_assume_aligned(p
, 16, 8);
38 clang_analyzer_eval(p
== q
); // expected-warning{{TRUE}}
41 void test_assume_aligned_3(char *p
) {
44 q
= __builtin_assume_aligned(p
, 16, 8);
45 clang_analyzer_eval(p
== q
); // expected-warning{{TRUE}}
48 void test_assume_aligned_4(char *p
) {
51 q
= (char*) __builtin_assume_aligned(p
+ 1, 16);
52 clang_analyzer_eval(p
== q
); // expected-warning{{FALSE}}
56 __builtin_assume(i
< 10);
57 clang_analyzer_eval(i
< 15); // expected-warning {{TRUE}}
62 __builtin_assume(i
< 5);
63 clang_analyzer_warnIfReached(); // Assumtion contradicts constraints.
64 // We give up the analysis on this path.
68 void test_constant_p(void *ptr
) {
72 clang_analyzer_eval(__builtin_constant_p(42) == 1); // expected-warning {{TRUE}}
73 clang_analyzer_eval(__builtin_constant_p(i
) == 0); // expected-warning {{TRUE}}
74 clang_analyzer_eval(__builtin_constant_p(j
) == 1); // expected-warning {{TRUE}}
75 clang_analyzer_eval(__builtin_constant_p(k
) == 1); // expected-warning {{TRUE}}
76 clang_analyzer_eval(__builtin_constant_p(i
+ 42) == 0); // expected-warning {{TRUE}}
77 clang_analyzer_eval(__builtin_constant_p(j
+ 42) == 1); // expected-warning {{TRUE}}
78 clang_analyzer_eval(__builtin_constant_p(k
+ 42) == 1); // expected-warning {{TRUE}}
79 clang_analyzer_eval(__builtin_constant_p(" ") == 1); // expected-warning {{TRUE}}
80 clang_analyzer_eval(__builtin_constant_p(test_constant_p
) == 0); // expected-warning {{TRUE}}
81 clang_analyzer_eval(__builtin_constant_p(k
- 3) == 0); // expected-warning {{FALSE}}
82 clang_analyzer_eval(__builtin_constant_p(k
- 3) == 1); // expected-warning {{TRUE}}
83 clang_analyzer_eval(__builtin_constant_p(ptr
== 0)); // expected-warning {{FALSE}}