blob: 4e7f0ad5b32d8989e280035ab0ceb5423583f2d5 [file] [log] [blame]
Ted Kremenek2dabd422009-01-22 18:53:15 +00001// RUN: clang -analyze -checker-cfref --analyzer-store-basic --verify -fblocks %s &&
2// RUN: clang -analyze -checker-cfref --analyzer-store-region --verify -fblocks %s
3
Ted Kremenek9f67ede2008-10-01 05:05:46 +00004
5// Reduced test case from crash in <rdar://problem/6253157>
6@class NSObject;
7@interface A @end
8@implementation A
9- (void)foo:(void (^)(NSObject *x))block {
10 if (!((block != ((void *)0)))) {}
11}
12@end
13
Ted Kremenek6dfe2f52008-10-18 22:20:20 +000014// Reduced test case from crash in PR 2796;
15// http://llvm.org/bugs/show_bug.cgi?id=2796
16
17unsigned foo(unsigned x) { return __alignof__((x)) + sizeof(x); }
Ted Kremenek9253b0f2008-10-20 23:14:31 +000018
19// Improvement to path-sensitivity involving compound assignments.
20// Addresses false positive in <rdar://problem/6268365>
21//
22
23unsigned r6268365Aux();
24
25void r6268365() {
26 unsigned x = 0;
27 x &= r6268365Aux();
28 unsigned j = 0;
29
30 if (x == 0) ++j;
31 if (x == 0) x = x / j; // no-warning
32}
33
Ted Kremenekc13b6e22008-10-20 23:40:25 +000034void divzeroassume(unsigned x, unsigned j) {
35 x /= j;
36 if (j == 0) x /= 0; // no-warning
37 if (j == 0) x /= j; // no-warning
38 if (j == 0) x = x / 0; // no-warning
39}
40
41void divzeroassumeB(unsigned x, unsigned j) {
42 x = x / j;
43 if (j == 0) x /= 0; // no-warning
44 if (j == 0) x /= j; // no-warning
45 if (j == 0) x = x / 0; // no-warning
46}
47
Ted Kremenek76dba7b2008-11-13 05:05:34 +000048// InitListExpr processing
49
50typedef float __m128 __attribute__((__vector_size__(16), __may_alias__));
51__m128 return128() {
Ted Kremenek062e2f92008-11-13 06:10:40 +000052 // This compound literal has a Vector type. We currently just
53 // return UnknownVal.
Ted Kremenek76dba7b2008-11-13 05:05:34 +000054 return __extension__(__m128) { 0.0f, 0.0f, 0.0f, 0.0f };
55}
56
Ted Kremenek062e2f92008-11-13 06:10:40 +000057typedef long long __v2di __attribute__ ((__vector_size__ (16)));
58typedef long long __m128i __attribute__ ((__vector_size__ (16), __may_alias__));
59__m128i vec128i(long long __q1, long long __q0) {
60 // This compound literal returns true for both isVectorType() and
61 // isIntegerType().
62 return __extension__ (__m128i)(__v2di){ __q0, __q1 };
63}
64
Ted Kremenek8322d6a2008-12-09 00:14:48 +000065// Zero-sized VLAs.
66void check_zero_sized_VLA(int x) {
67 if (x)
68 return;
69
Ted Kremenek159d2482008-12-09 00:44:16 +000070 int vla[x]; // expected-warning{{VLAs with no elements have undefined behavior}}
71}
72
73void check_uninit_sized_VLA() {
74 int x;
75 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 +000076}
Ted Kremenek062e2f92008-11-13 06:10:40 +000077
Ted Kremenek55f7bcb2008-12-15 18:51:00 +000078// sizeof(void)
79// - Tests a regression reported in PR 3211: http://llvm.org/bugs/show_bug.cgi?id=3211
80void handle_sizeof_void(unsigned flag) {
81 int* p = 0;
82
83 if (flag) {
84 if (sizeof(void) == 1)
85 return;
86 // Infeasible.
87 *p = 1; // no-warning
88 }
89
90 void* q;
91
92 if (!flag) {
93 if (sizeof(*q) == 1)
94 return;
95 // Infeasibe.
96 *p = 1; // no-warning
97 }
98
99 // Infeasible.
100 *p = 1; // no-warning
101}
102
Ted Kremenekd76d47e2009-01-27 18:29:03 +0000103// PR 3422
104void pr3422_helper(char *p);
105void pr3422() {
106 char buf[100];
107 char *q = &buf[10];
108 pr3422_helper(&q[1]);
109}
110