Ted Kremenek | e5cfd52 | 2011-05-25 23:57:29 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -disable-free -analyzer-eagerly-assume -analyzer-checker=core -analyzer-checker=deadcode -verify %s |
| 2 | |
| 3 | unsigned long strlen(const char *); |
| 4 | |
| 5 | int size_rdar9373039 = 1; |
| 6 | int 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 | |
| 22 | int foo_rdar9373039(const char *); |
| 23 | |
| 24 | int 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 | |
Jordy Rose | 22043b5 | 2011-06-08 22:47:39 +0000 | [diff] [blame] | 39 | |
| 40 | int 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 | |
| 46 | int 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 | |
Jordy Rose | 7fead31 | 2011-06-09 05:44:04 +0000 | [diff] [blame] | 53 | int 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 | |
| 59 | int 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 | |
Jordy Rose | ac73ea8 | 2011-06-10 08:49:37 +0000 | [diff] [blame] | 65 | int 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 | |
| 72 | int 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 | } |
Ted Kremenek | beedc5f | 2011-10-20 19:33:06 +0000 | [diff] [blame] | 84 | |
| 85 | // This previously crashed logic in the analyzer engine when evaluating locations. |
| 86 | void rdar10308201_aux(unsigned val); |
| 87 | void 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 | |
Anna Zaks | cdcc653 | 2011-11-01 22:41:06 +0000 | [diff] [blame] | 98 | typedef struct Struct103 { |
| 99 | unsigned i; |
| 100 | } Struct103; |
| 101 | typedef unsigned int size_t; |
| 102 | void __my_memset_chk(char*, int, size_t); |
| 103 | static 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 | } |
Ted Kremenek | beedc5f | 2011-10-20 19:33:06 +0000 | [diff] [blame] | 108 | |
Anna Zaks | 2d950b1 | 2011-11-01 22:41:14 +0000 | [diff] [blame] | 109 | /* Caching out on a sink node. */ |
| 110 | extern int fooR10376675(); |
| 111 | extern int* bazR10376675(); |
| 112 | extern int nR10376675; |
| 113 | void barR10376675(int *x) { |
| 114 | int *pm; |
| 115 | if (nR10376675 * 2) { |
| 116 | int *pk = bazR10376675(); |
| 117 | pm = pk; //expected-warning {{never read}} |
| 118 | } |
| 119 | do { |
| 120 | *x = fooR10376675(); |
| 121 | } while (0); |
| 122 | } |
Ted Kremenek | 729aa06 | 2011-11-14 20:05:54 +0000 | [diff] [blame^] | 123 | |
| 124 | // Test accesses to wide character strings doesn't break the analyzer. |
| 125 | typedef int wchar_t; |
| 126 | struct rdar10385775 { |
| 127 | wchar_t *name; |
| 128 | }; |
| 129 | void RDar10385775(struct rdar10385775* p) { |
| 130 | p->name = L"a"; |
| 131 | } |