misc-ps.c revision cdcc653642d4ac9255c574fabe74a48149e06733
1// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -disable-free -analyzer-eagerly-assume -analyzer-checker=core -analyzer-checker=deadcode -verify %s 2 3unsigned long strlen(const char *); 4 5int size_rdar9373039 = 1; 6int rdar9373039() { 7 int x; 8 int j = 0; 9 10 for (int i = 0 ; i < size_rdar9373039 ; ++i) 11 x = 1; 12 13 // strlen doesn't invalidate the value of 'size_rdar9373039'. 14 int extra = (2 + strlen ("Clang") + ((4 - ((unsigned int) (2 + strlen ("Clang")) % 4)) % 4)) + (2 + strlen ("1.0") + ((4 - ((unsigned int) (2 + strlen ("1.0")) % 4)) % 4)); 15 16 for (int i = 0 ; i < size_rdar9373039 ; ++i) 17 j += x; // no-warning 18 19 return j; 20} 21 22int foo_rdar9373039(const char *); 23 24int rdar93730392() { 25 int x; 26 int j = 0; 27 28 for (int i = 0 ; i < size_rdar9373039 ; ++i) 29 x = 1; 30 31 int extra = (2 + foo_rdar9373039 ("Clang") + ((4 - ((unsigned int) (2 + foo_rdar9373039 ("Clang")) % 4)) % 4)) + (2 + foo_rdar9373039 ("1.0") + ((4 - ((unsigned int) (2 + foo_rdar9373039 ("1.0")) % 4)) % 4)); // expected-warning {{never read}} 32 33 for (int i = 0 ; i < size_rdar9373039 ; ++i) 34 j += x; // expected-warning {{garbage}} 35 36 return j; 37} 38 39 40int PR8962 (int *t) { 41 // This should look through the __extension__ no-op. 42 if (__extension__ (t)) return 0; 43 return *t; // expected-warning {{null pointer}} 44} 45 46int PR8962_b (int *t) { 47 // This should still ignore the nested casts 48 // which aren't handled by a single IgnoreParens() 49 if (((int)((int)t))) return 0; 50 return *t; // expected-warning {{null pointer}} 51} 52 53int PR8962_c (int *t) { 54 // If the last element in a StmtExpr was a ParenExpr, it's still live 55 if (({ (t ? (_Bool)0 : (_Bool)1); })) return 0; 56 return *t; // no-warning 57} 58 59int PR8962_d (int *t) { 60 // If the last element in a StmtExpr is an __extension__, it's still live 61 if (({ __extension__(t ? (_Bool)0 : (_Bool)1); })) return 0; 62 return *t; // no-warning 63} 64 65int PR8962_e (int *t) { 66 // Redundant casts can mess things up! 67 // Environment used to skip through NoOp casts, but LiveVariables didn't! 68 if (({ (t ? (int)(int)0L : (int)(int)1L); })) return 0; 69 return *t; // no-warning 70} 71 72int PR8962_f (int *t) { 73 // The StmtExpr isn't a block-level expression here, 74 // the __extension__ is. But the value should be attached to the StmtExpr 75 // anyway. Make sure the block-level check is /before/ IgnoreParens. 76 if ( __extension__({ 77 _Bool r; 78 if (t) r = 0; 79 else r = 1; 80 r; 81 }) ) return 0; 82 return *t; // no-warning 83} 84 85// This previously crashed logic in the analyzer engine when evaluating locations. 86void rdar10308201_aux(unsigned val); 87void rdar10308201 (int valA, void *valB, unsigned valC) { 88 unsigned actual_base, lines; 89 if (valC == 0) { 90 actual_base = (unsigned)valB; 91 for (;;) { 92 if (valA & (1<<0)) 93 rdar10308201_aux(actual_base); 94 } 95 } 96} 97 98typedef struct Struct103 { 99 unsigned i; 100} Struct103; 101typedef unsigned int size_t; 102void __my_memset_chk(char*, int, size_t); 103static int radar10367606(int t) { 104 Struct103 overall; 105 ((__builtin_object_size ((char *) &overall, 0) != (size_t) -1) ? __builtin___memset_chk ((char *) &overall, 0, sizeof(Struct103), __builtin_object_size ((char *) &overall, 0)) : __my_memset_chk ((char *) &overall, 0, sizeof(Struct103))); 106 return 0; 107} 108 109