blob: 02a7d8202088a5234271aa688573a6df19f0b0b1 [file] [log] [blame]
Ted Kremenek3092dd62009-02-17 19:29:07 +00001// RUN: clang -analyze -checker-cfref --analyzer-store=basic -analyzer-constraints=basic --verify -fblocks %s &&
2// RUN: clang -analyze -checker-cfref --analyzer-store=basic -analyzer-constraints=range --verify -fblocks %s &&
3// RUN: clang -analyze -checker-cfref --analyzer-store=region -analyzer-constraints=basic --verify -fblocks %s &&
4// RUN: clang -analyze -checker-cfref --analyzer-store=region -analyzer-constraints=range --verify -fblocks %s
Ted Kremenek2dabd422009-01-22 18:53:15 +00005
Ted Kremenek9f67ede2008-10-01 05:05:46 +00006
7// Reduced test case from crash in <rdar://problem/6253157>
8@class NSObject;
9@interface A @end
10@implementation A
11- (void)foo:(void (^)(NSObject *x))block {
12 if (!((block != ((void *)0)))) {}
13}
14@end
15
Ted Kremenek6dfe2f52008-10-18 22:20:20 +000016// Reduced test case from crash in PR 2796;
17// http://llvm.org/bugs/show_bug.cgi?id=2796
18
19unsigned foo(unsigned x) { return __alignof__((x)) + sizeof(x); }
Ted Kremenek9253b0f2008-10-20 23:14:31 +000020
21// Improvement to path-sensitivity involving compound assignments.
22// Addresses false positive in <rdar://problem/6268365>
23//
24
25unsigned r6268365Aux();
26
27void r6268365() {
28 unsigned x = 0;
29 x &= r6268365Aux();
30 unsigned j = 0;
31
32 if (x == 0) ++j;
33 if (x == 0) x = x / j; // no-warning
34}
35
Ted Kremenekc13b6e22008-10-20 23:40:25 +000036void divzeroassume(unsigned x, unsigned j) {
37 x /= j;
38 if (j == 0) x /= 0; // no-warning
39 if (j == 0) x /= j; // no-warning
40 if (j == 0) x = x / 0; // no-warning
41}
42
43void divzeroassumeB(unsigned x, unsigned j) {
44 x = x / j;
45 if (j == 0) x /= 0; // no-warning
46 if (j == 0) x /= j; // no-warning
47 if (j == 0) x = x / 0; // no-warning
48}
49
Ted Kremenek76dba7b2008-11-13 05:05:34 +000050// InitListExpr processing
51
52typedef float __m128 __attribute__((__vector_size__(16), __may_alias__));
53__m128 return128() {
Ted Kremenek062e2f92008-11-13 06:10:40 +000054 // This compound literal has a Vector type. We currently just
55 // return UnknownVal.
Ted Kremenek76dba7b2008-11-13 05:05:34 +000056 return __extension__(__m128) { 0.0f, 0.0f, 0.0f, 0.0f };
57}
58
Ted Kremenek062e2f92008-11-13 06:10:40 +000059typedef long long __v2di __attribute__ ((__vector_size__ (16)));
60typedef long long __m128i __attribute__ ((__vector_size__ (16), __may_alias__));
61__m128i vec128i(long long __q1, long long __q0) {
62 // This compound literal returns true for both isVectorType() and
63 // isIntegerType().
64 return __extension__ (__m128i)(__v2di){ __q0, __q1 };
65}
66
Ted Kremenek8322d6a2008-12-09 00:14:48 +000067// Zero-sized VLAs.
68void check_zero_sized_VLA(int x) {
69 if (x)
70 return;
71
Ted Kremenek159d2482008-12-09 00:44:16 +000072 int vla[x]; // expected-warning{{VLAs with no elements have undefined behavior}}
73}
74
75void check_uninit_sized_VLA() {
76 int x;
77 int vla[x]; // expected-warning{{The expression used to specify the number of elements in the VLA 'vla' evaluates to an undefined or garbage value.}}
Ted Kremenek8322d6a2008-12-09 00:14:48 +000078}
Ted Kremenek062e2f92008-11-13 06:10:40 +000079
Ted Kremenek55f7bcb2008-12-15 18:51:00 +000080// sizeof(void)
81// - Tests a regression reported in PR 3211: http://llvm.org/bugs/show_bug.cgi?id=3211
82void handle_sizeof_void(unsigned flag) {
83 int* p = 0;
84
85 if (flag) {
86 if (sizeof(void) == 1)
87 return;
88 // Infeasible.
89 *p = 1; // no-warning
90 }
91
92 void* q;
93
94 if (!flag) {
95 if (sizeof(*q) == 1)
96 return;
97 // Infeasibe.
98 *p = 1; // no-warning
99 }
100
101 // Infeasible.
102 *p = 1; // no-warning
103}
104
Ted Kremenekd76d47e2009-01-27 18:29:03 +0000105// PR 3422
106void pr3422_helper(char *p);
107void pr3422() {
108 char buf[100];
109 char *q = &buf[10];
110 pr3422_helper(&q[1]);
111}
112
Ted Kremeneka3d1eb82009-02-14 05:55:08 +0000113// PR 3543 (handle empty statement expressions)
114int pr_3543(void) {
115 ({});
116}
117
Ted Kremenek265a3052009-02-24 02:23:11 +0000118// <rdar://problem/6611677>
119// This test case test the use of a vector type within an array subscript
120// expression.
121typedef long long __a64vector __attribute__((__vector_size__(8)));
122typedef long long __a128vector __attribute__((__vector_size__(16)));
123static inline __a64vector __attribute__((__always_inline__, __nodebug__))
124my_test_mm_movepi64_pi64(__a128vector a) {
125 return (__a64vector)a[0];
126}
127
Ted Kremeneka3d1eb82009-02-14 05:55:08 +0000128