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