misc-ps.m revision d76d47eb5f5afffcf25fe8c42521867ccad4073b
1// RUN: clang -analyze -checker-cfref --analyzer-store-basic --verify -fblocks %s && 2// RUN: clang -analyze -checker-cfref --analyzer-store-region --verify -fblocks %s 3 4 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 14// 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); } 18 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 34void 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 48// InitListExpr processing 49 50typedef float __m128 __attribute__((__vector_size__(16), __may_alias__)); 51__m128 return128() { 52 // This compound literal has a Vector type. We currently just 53 // return UnknownVal. 54 return __extension__(__m128) { 0.0f, 0.0f, 0.0f, 0.0f }; 55} 56 57typedef 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 65// Zero-sized VLAs. 66void check_zero_sized_VLA(int x) { 67 if (x) 68 return; 69 70 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.}} 76} 77 78// 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 103// 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 111