1 // RUN: %clang_analyze_cc1 -triple i386-apple-darwin10 -w -Wno-int-conversion -analyzer-checker=osx.NumberObjectConversion %s -verify
2 // RUN: %clang_analyze_cc1 -triple i386-apple-darwin10 -w -Wno-int-conversion -analyzer-checker=osx.NumberObjectConversion -analyzer-config osx.NumberObjectConversion:Pedantic=true -DPEDANTIC %s -verify
4 #define NULL ((void *)0)
6 typedef const struct __CFNumber
*CFNumberRef
;
10 void bad(CFNumberRef p
) {
12 if (p
) {} // expected-warning{{Converting a pointer value of type 'CFNumberRef' to a primitive boolean value; instead, either compare the pointer to NULL or call CFNumberGetValue()}}
13 if (!p
) {} // expected-warning{{Converting a pointer value of type 'CFNumberRef' to a primitive boolean value; instead, either compare the pointer to NULL or call CFNumberGetValue()}}
14 p
? 1 : 2; // expected-warning{{Converting a pointer value of type 'CFNumberRef' to a primitive boolean value; instead, either compare the pointer to NULL or call CFNumberGetValue()}}
15 if (p
== 0) {} // expected-warning{{Comparing a pointer value of type 'CFNumberRef' to a primitive integer value; instead, either compare the pointer to NULL or compare the result of calling CFNumberGetValue()}}
17 if (p
) {} // no-warning
18 if (!p
) {} // no-warning
19 p
? 1 : 2; // no-warning
20 if (p
== 0) {} // no-warning
22 if (p
> 0) {} // expected-warning{{Comparing a pointer value of type 'CFNumberRef' to a primitive integer value; did you mean to compare the result of calling CFNumberGetValue()?}}
23 int x
= p
; // expected-warning{{Converting a pointer value of type 'CFNumberRef' to a primitive integer value; did you mean to call CFNumberGetValue()?}}
24 x
= p
; // expected-warning{{Converting a pointer value of type 'CFNumberRef' to a primitive integer value; did you mean to call CFNumberGetValue()?}}
25 takes_int(p
); // expected-warning{{Converting a pointer value of type 'CFNumberRef' to a primitive integer value; did you mean to call CFNumberGetValue()?}}
26 takes_int(x
); // no-warning
29 // Conversion of a pointer to an intptr_t is fine.
30 typedef long intptr_t;
31 typedef unsigned long uintptr_t;
32 typedef long fintptr_t
; // Fake, for testing the regex.
33 void test_intptr_t(CFNumberRef p
) {
34 (long)p
; // expected-warning{{Converting a pointer value of type 'CFNumberRef' to a primitive integer value; did you mean to call CFNumberGetValue()?}}
35 (intptr_t)p
; // no-warning
36 (unsigned long)p
; // expected-warning{{Converting a pointer value of type 'CFNumberRef' to a primitive integer value; did you mean to call CFNumberGetValue()?}}
37 (uintptr_t)p
; // no-warning
38 (fintptr_t
)p
; // expected-warning{{Converting a pointer value of type 'CFNumberRef' to a primitive integer value; did you mean to call CFNumberGetValue()?}}