1 // Force x86-64 because some of our heuristics are actually based
4 // RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -verify -std=c++11 %s
6 namespace RuntimeBehavior
{
7 // Avoid emitting tautological compare warnings when the code already has
8 // compile time checks on variable sizes.
10 const int kintmax
= 2147483647;
12 if (sizeof(x
) < sizeof(int) || x
< kintmax
) {}
15 // expected-warning@-1{{comparison of constant 2147483647 with expression of type 'short' is always true}}
20 // expected-warning@-1{{comparison of constant 2147483647 with expression of type 'short' is always true}}
22 if (sizeof(x
) < sizeof(int))
29 namespace ArrayCompare
{
30 #define GetValue(ptr) ((ptr != 0) ? ptr[0] : 0)
31 extern int a
[] __attribute__((weak
));
36 const char str
[] = "text";
44 // expected-warning@-1{{comparison of array 'b' equal to a null pointer is always false}}
46 // expected-warning@-1{{comparison of array 'b' not equal to a null pointer is always true}}
48 // expected-warning@-1{{comparison of array 'b' equal to a null pointer is always false}}
50 // expected-warning@-1{{comparison of array 'b' not equal to a null pointer is always true}}
52 // expected-warning@-1{{comparison of array 'c.x' equal to a null pointer is always false}}
54 // expected-warning@-1{{comparison of array 'c.x' not equal to a null pointer is always true}}
56 // expected-warning@-1{{comparison of array 'str' equal to a null pointer is always false}}
58 // expected-warning@-1{{comparison of array 'str' not equal to a null pointer is always true}}
62 namespace FunctionCompare
{
63 #define CallFunction(f) ((f != 0) ? f() : 0)
64 extern void a() __attribute__((weak
));
76 (void)CallFunction(fun2
);
80 // expected-warning@-1{{comparison of function 'fun1' equal to a null pointer is always false}}
81 // expected-note@-2{{prefix with the address-of operator to silence this warning}}
83 // expected-warning@-1{{comparison of function 'fun2' equal to a null pointer is always false}}
84 // expected-note@-2{{prefix with the address-of operator to silence this warning}}
85 // expected-note@-3{{suffix with parentheses to turn this into a function call}}
87 // expected-warning@-1{{comparison of function 'fun3' equal to a null pointer is always false}}
88 // expected-note@-2{{prefix with the address-of operator to silence this warning}}
89 // expected-note@-3{{suffix with parentheses to turn this into a function call}}
91 // expected-warning@-1{{comparison of function 'fun4' equal to a null pointer is always false}}
92 // expected-note@-2{{prefix with the address-of operator to silence this warning}}
93 if (nullptr != fun1
) {}
94 // expected-warning@-1{{comparison of function 'fun1' not equal to a null pointer is always true}}
95 // expected-note@-2{{prefix with the address-of operator to silence this warning}}
96 if (nullptr != fun2
) {}
97 // expected-warning@-1{{comparison of function 'fun2' not equal to a null pointer is always true}}
98 // expected-note@-2{{prefix with the address-of operator to silence this warning}}
99 if (nullptr != fun3
) {}
100 // expected-warning@-1{{comparison of function 'fun3' not equal to a null pointer is always true}}
101 // expected-note@-2{{prefix with the address-of operator to silence this warning}}
102 // expected-note@-3{{suffix with parentheses to turn this into a function call}}
103 if (nullptr != fun4
) {}
104 // expected-warning@-1{{comparison of function 'fun4' not equal to a null pointer is always true}}
105 // expected-note@-2{{prefix with the address-of operator to silence this warning}}
107 // expected-warning@-1{{comparison of function 'S::foo' equal to a null pointer is always false}}
108 // expected-note@-2{{prefix with the address-of operator to silence this warning}}
109 // expected-note@-3{{suffix with parentheses to turn this into a function call}}
113 namespace PointerCompare
{
114 extern int a
__attribute__((weak
));
128 // expected-warning@-1{{comparison of address of 'b' equal to a null pointer is always false}}
130 // expected-warning@-1{{comparison of address of 'c' equal to a null pointer is always false}}
132 // expected-warning@-1{{comparison of address of 's.a' equal to a null pointer is always false}}
134 // expected-warning@-1{{comparison of address of 's.b' equal to a null pointer is always false}}
136 // expected-warning@-1{{comparison of address of 'S::a' equal to a null pointer is always false}}
141 #define assert(x) if (x) {}
148 // expected-warning@-1{{comparison of array 'array' equal to a null pointer is always false}}
150 // expected-warning@-1{{comparison of array 'array' not equal to a null pointer is always true}}
151 assert(array
== 0 && "expecting null pointer");
152 // expected-warning@-1{{comparison of array 'array' equal to a null pointer is always false}}
153 assert(array
!= 0 && "expecting non-null pointer");
154 // expected-warning@-1{{comparison of array 'array' not equal to a null pointer is always true}}
157 // expected-warning@-1{{comparison of function 'fun' equal to a null pointer is always false}}
158 // expected-note@-2{{prefix with the address-of operator to silence this warning}}
160 // expected-warning@-1{{comparison of function 'fun' not equal to a null pointer is always true}}
161 // expected-note@-2{{prefix with the address-of operator to silence this warning}}
162 assert(fun
== 0 && "expecting null pointer");
163 // expected-warning@-1{{comparison of function 'fun' equal to a null pointer is always false}}
164 // expected-note@-2{{prefix with the address-of operator to silence this warning}}
165 assert(fun
!= 0 && "expecting non-null pointer");
166 // expected-warning@-1{{comparison of function 'fun' not equal to a null pointer is always true}}
167 // expected-note@-2{{prefix with the address-of operator to silence this warning}}
170 // expected-warning@-1{{comparison of address of 'x' equal to a null pointer is always false}}
172 // expected-warning@-1{{comparison of address of 'x' not equal to a null pointer is always true}}
173 assert(&x
== 0 && "expecting null pointer");
174 // expected-warning@-1{{comparison of address of 'x' equal to a null pointer is always false}}
175 assert(&x
!= 0 && "expecting non-null pointer");
176 // expected-warning@-1{{comparison of address of 'x' not equal to a null pointer is always true}}