2009-02-18 03:29:07 +08:00
|
|
|
// RUN: clang -analyze -checker-cfref --analyzer-store=basic -analyzer-constraints=basic --verify -fblocks %s &&
|
|
|
|
// RUN: clang -analyze -checker-cfref --analyzer-store=basic -analyzer-constraints=range --verify -fblocks %s &&
|
|
|
|
// RUN: clang -analyze -checker-cfref --analyzer-store=region -analyzer-constraints=basic --verify -fblocks %s &&
|
|
|
|
// RUN: clang -analyze -checker-cfref --analyzer-store=region -analyzer-constraints=range --verify -fblocks %s
|
2009-01-23 02:53:15 +08:00
|
|
|
|
2008-10-01 13:05:46 +08:00
|
|
|
|
|
|
|
// Reduced test case from crash in <rdar://problem/6253157>
|
|
|
|
@class NSObject;
|
|
|
|
@interface A @end
|
|
|
|
@implementation A
|
|
|
|
- (void)foo:(void (^)(NSObject *x))block {
|
|
|
|
if (!((block != ((void *)0)))) {}
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
2008-10-19 06:20:20 +08:00
|
|
|
// Reduced test case from crash in PR 2796;
|
|
|
|
// http://llvm.org/bugs/show_bug.cgi?id=2796
|
|
|
|
|
|
|
|
unsigned foo(unsigned x) { return __alignof__((x)) + sizeof(x); }
|
2008-10-21 07:14:31 +08:00
|
|
|
|
|
|
|
// Improvement to path-sensitivity involving compound assignments.
|
|
|
|
// Addresses false positive in <rdar://problem/6268365>
|
|
|
|
//
|
|
|
|
|
|
|
|
unsigned r6268365Aux();
|
|
|
|
|
|
|
|
void r6268365() {
|
|
|
|
unsigned x = 0;
|
|
|
|
x &= r6268365Aux();
|
|
|
|
unsigned j = 0;
|
|
|
|
|
|
|
|
if (x == 0) ++j;
|
|
|
|
if (x == 0) x = x / j; // no-warning
|
|
|
|
}
|
|
|
|
|
2008-10-21 07:40:25 +08:00
|
|
|
void divzeroassume(unsigned x, unsigned j) {
|
|
|
|
x /= j;
|
|
|
|
if (j == 0) x /= 0; // no-warning
|
|
|
|
if (j == 0) x /= j; // no-warning
|
|
|
|
if (j == 0) x = x / 0; // no-warning
|
|
|
|
}
|
|
|
|
|
|
|
|
void divzeroassumeB(unsigned x, unsigned j) {
|
|
|
|
x = x / j;
|
|
|
|
if (j == 0) x /= 0; // no-warning
|
|
|
|
if (j == 0) x /= j; // no-warning
|
|
|
|
if (j == 0) x = x / 0; // no-warning
|
|
|
|
}
|
|
|
|
|
2008-11-13 13:05:34 +08:00
|
|
|
// InitListExpr processing
|
|
|
|
|
|
|
|
typedef float __m128 __attribute__((__vector_size__(16), __may_alias__));
|
|
|
|
__m128 return128() {
|
2008-11-13 14:10:40 +08:00
|
|
|
// This compound literal has a Vector type. We currently just
|
|
|
|
// return UnknownVal.
|
2008-11-13 13:05:34 +08:00
|
|
|
return __extension__(__m128) { 0.0f, 0.0f, 0.0f, 0.0f };
|
|
|
|
}
|
|
|
|
|
2008-11-13 14:10:40 +08:00
|
|
|
typedef long long __v2di __attribute__ ((__vector_size__ (16)));
|
|
|
|
typedef long long __m128i __attribute__ ((__vector_size__ (16), __may_alias__));
|
|
|
|
__m128i vec128i(long long __q1, long long __q0) {
|
|
|
|
// This compound literal returns true for both isVectorType() and
|
|
|
|
// isIntegerType().
|
|
|
|
return __extension__ (__m128i)(__v2di){ __q0, __q1 };
|
|
|
|
}
|
|
|
|
|
2008-12-09 08:14:48 +08:00
|
|
|
// Zero-sized VLAs.
|
|
|
|
void check_zero_sized_VLA(int x) {
|
|
|
|
if (x)
|
|
|
|
return;
|
|
|
|
|
2008-12-09 08:44:16 +08:00
|
|
|
int vla[x]; // expected-warning{{VLAs with no elements have undefined behavior}}
|
|
|
|
}
|
|
|
|
|
|
|
|
void check_uninit_sized_VLA() {
|
|
|
|
int x;
|
|
|
|
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.}}
|
2008-12-09 08:14:48 +08:00
|
|
|
}
|
2008-11-13 14:10:40 +08:00
|
|
|
|
2008-12-16 02:51:00 +08:00
|
|
|
// sizeof(void)
|
|
|
|
// - Tests a regression reported in PR 3211: http://llvm.org/bugs/show_bug.cgi?id=3211
|
|
|
|
void handle_sizeof_void(unsigned flag) {
|
|
|
|
int* p = 0;
|
|
|
|
|
|
|
|
if (flag) {
|
|
|
|
if (sizeof(void) == 1)
|
|
|
|
return;
|
|
|
|
// Infeasible.
|
|
|
|
*p = 1; // no-warning
|
|
|
|
}
|
|
|
|
|
|
|
|
void* q;
|
|
|
|
|
|
|
|
if (!flag) {
|
|
|
|
if (sizeof(*q) == 1)
|
|
|
|
return;
|
|
|
|
// Infeasibe.
|
|
|
|
*p = 1; // no-warning
|
|
|
|
}
|
|
|
|
|
|
|
|
// Infeasible.
|
|
|
|
*p = 1; // no-warning
|
|
|
|
}
|
|
|
|
|
2009-01-28 02:29:03 +08:00
|
|
|
// PR 3422
|
|
|
|
void pr3422_helper(char *p);
|
|
|
|
void pr3422() {
|
|
|
|
char buf[100];
|
|
|
|
char *q = &buf[10];
|
|
|
|
pr3422_helper(&q[1]);
|
|
|
|
}
|
|
|
|
|
2009-02-14 13:55:08 +08:00
|
|
|
// PR 3543 (handle empty statement expressions)
|
|
|
|
int pr_3543(void) {
|
|
|
|
({});
|
|
|
|
}
|
|
|
|
|
2009-02-24 10:23:11 +08:00
|
|
|
// <rdar://problem/6611677>
|
|
|
|
// This test case test the use of a vector type within an array subscript
|
|
|
|
// expression.
|
|
|
|
typedef long long __a64vector __attribute__((__vector_size__(8)));
|
|
|
|
typedef long long __a128vector __attribute__((__vector_size__(16)));
|
|
|
|
static inline __a64vector __attribute__((__always_inline__, __nodebug__))
|
|
|
|
my_test_mm_movepi64_pi64(__a128vector a) {
|
|
|
|
return (__a64vector)a[0];
|
|
|
|
}
|
|
|
|
|
2009-02-14 13:55:08 +08:00
|
|
|
|