1 // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -analyzer-checker=core,debug.ExprInspection %s -std=c++11 -verify
2
3 void clang_analyzer_eval(bool);
4
testAddressof(int x)5 void testAddressof(int x) {
6 clang_analyzer_eval(&x == __builtin_addressof(x)); // expected-warning{{TRUE}}
7 }
8
testSize()9 void testSize() {
10 struct {
11 int x;
12 int y;
13 char z;
14 } object;
15 clang_analyzer_eval(__builtin_object_size(&object.y, 0) == sizeof(object) - sizeof(int)); // expected-warning{{TRUE}}
16
17 // Clang can't actually evaluate these builtin "calls", but importantly they don't actually evaluate the argument expression either.
18 int i = 0;
19 char buf[10];
20 clang_analyzer_eval(__builtin_object_size(&buf[i++], 0) == sizeof(buf)); // expected-warning{{FALSE}}
21 clang_analyzer_eval(__builtin_object_size(&buf[++i], 0) == sizeof(buf) - 1); // expected-warning{{FALSE}}
22
23 clang_analyzer_eval(i == 0); // expected-warning{{TRUE}}
24 }
25
test_assume_aligned_1(char * p)26 void test_assume_aligned_1(char *p) {
27 char *q;
28
29 q = (char*) __builtin_assume_aligned(p, 16);
30 clang_analyzer_eval(p == q); // expected-warning{{TRUE}}
31 }
32
test_assume_aligned_2(char * p)33 void test_assume_aligned_2(char *p) {
34 char *q;
35
36 q = (char*) __builtin_assume_aligned(p, 16, 8);
37 clang_analyzer_eval(p == q); // expected-warning{{TRUE}}
38 }
39
test_assume_aligned_3(char * p)40 void test_assume_aligned_3(char *p) {
41 void *q;
42
43 q = __builtin_assume_aligned(p, 16, 8);
44 clang_analyzer_eval(p == q); // expected-warning{{TRUE}}
45 }
46
test_assume_aligned_4(char * p)47 void test_assume_aligned_4(char *p) {
48 char *q;
49
50 q = (char*) __builtin_assume_aligned(p + 1, 16);
51 clang_analyzer_eval(p == q); // expected-warning{{FALSE}}
52 }
53