misc-ps.m revision 3092dd6b2c01d7d1721a29c865ac729cd8f9ea3c
1// 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 5 6 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 16// 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); } 20 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 36void 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 50// InitListExpr processing 51 52typedef float __m128 __attribute__((__vector_size__(16), __may_alias__)); 53__m128 return128() { 54 // This compound literal has a Vector type. We currently just 55 // return UnknownVal. 56 return __extension__(__m128) { 0.0f, 0.0f, 0.0f, 0.0f }; 57} 58 59typedef 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 67// Zero-sized VLAs. 68void check_zero_sized_VLA(int x) { 69 if (x) 70 return; 71 72 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.}} 78} 79 80// 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 105// 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 113// PR 3543 (handle empty statement expressions) 114int pr_3543(void) { 115 ({}); 116} 117 118 119