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 | |
Ted Kremenek | e5cfd52 | 2011-05-25 23:57:29 +0000 | [diff] [blame] | 3 | int size_rdar9373039 = 1; |
Ted Kremenek | e5cfd52 | 2011-05-25 23:57:29 +0000 | [diff] [blame] | 4 | int foo_rdar9373039(const char *); |
| 5 | |
| 6 | int rdar93730392() { |
| 7 | int x; |
| 8 | int j = 0; |
| 9 | |
| 10 | for (int i = 0 ; i < size_rdar9373039 ; ++i) |
| 11 | x = 1; |
| 12 | |
| 13 | 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}} |
| 14 | |
| 15 | for (int i = 0 ; i < size_rdar9373039 ; ++i) |
| 16 | j += x; // expected-warning {{garbage}} |
| 17 | |
| 18 | return j; |
| 19 | } |
| 20 | |
Jordy Rose | 22043b5 | 2011-06-08 22:47:39 +0000 | [diff] [blame] | 21 | |
| 22 | int PR8962 (int *t) { |
| 23 | // This should look through the __extension__ no-op. |
| 24 | if (__extension__ (t)) return 0; |
| 25 | return *t; // expected-warning {{null pointer}} |
| 26 | } |
| 27 | |
| 28 | int PR8962_b (int *t) { |
| 29 | // This should still ignore the nested casts |
| 30 | // which aren't handled by a single IgnoreParens() |
| 31 | if (((int)((int)t))) return 0; |
| 32 | return *t; // expected-warning {{null pointer}} |
| 33 | } |
| 34 | |
Jordy Rose | 7fead31 | 2011-06-09 05:44:04 +0000 | [diff] [blame] | 35 | int PR8962_c (int *t) { |
| 36 | // If the last element in a StmtExpr was a ParenExpr, it's still live |
| 37 | if (({ (t ? (_Bool)0 : (_Bool)1); })) return 0; |
| 38 | return *t; // no-warning |
| 39 | } |
| 40 | |
| 41 | int PR8962_d (int *t) { |
| 42 | // If the last element in a StmtExpr is an __extension__, it's still live |
| 43 | if (({ __extension__(t ? (_Bool)0 : (_Bool)1); })) return 0; |
| 44 | return *t; // no-warning |
| 45 | } |
| 46 | |
Jordy Rose | ac73ea8 | 2011-06-10 08:49:37 +0000 | [diff] [blame] | 47 | int PR8962_e (int *t) { |
| 48 | // Redundant casts can mess things up! |
| 49 | // Environment used to skip through NoOp casts, but LiveVariables didn't! |
| 50 | if (({ (t ? (int)(int)0L : (int)(int)1L); })) return 0; |
| 51 | return *t; // no-warning |
| 52 | } |
| 53 | |
| 54 | int PR8962_f (int *t) { |
| 55 | // The StmtExpr isn't a block-level expression here, |
| 56 | // the __extension__ is. But the value should be attached to the StmtExpr |
| 57 | // anyway. Make sure the block-level check is /before/ IgnoreParens. |
| 58 | if ( __extension__({ |
| 59 | _Bool r; |
| 60 | if (t) r = 0; |
| 61 | else r = 1; |
| 62 | r; |
| 63 | }) ) return 0; |
| 64 | return *t; // no-warning |
| 65 | } |
Ted Kremenek | beedc5f | 2011-10-20 19:33:06 +0000 | [diff] [blame] | 66 | |
| 67 | // This previously crashed logic in the analyzer engine when evaluating locations. |
| 68 | void rdar10308201_aux(unsigned val); |
| 69 | void rdar10308201 (int valA, void *valB, unsigned valC) { |
| 70 | unsigned actual_base, lines; |
| 71 | if (valC == 0) { |
| 72 | actual_base = (unsigned)valB; |
| 73 | for (;;) { |
| 74 | if (valA & (1<<0)) |
| 75 | rdar10308201_aux(actual_base); |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 | |
Anna Zaks | cdcc653 | 2011-11-01 22:41:06 +0000 | [diff] [blame] | 80 | typedef struct Struct103 { |
| 81 | unsigned i; |
| 82 | } Struct103; |
| 83 | typedef unsigned int size_t; |
| 84 | void __my_memset_chk(char*, int, size_t); |
| 85 | static int radar10367606(int t) { |
| 86 | Struct103 overall; |
| 87 | ((__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))); |
| 88 | return 0; |
| 89 | } |
Ted Kremenek | beedc5f | 2011-10-20 19:33:06 +0000 | [diff] [blame] | 90 | |
Anna Zaks | 2d950b1 | 2011-11-01 22:41:14 +0000 | [diff] [blame] | 91 | /* Caching out on a sink node. */ |
| 92 | extern int fooR10376675(); |
| 93 | extern int* bazR10376675(); |
| 94 | extern int nR10376675; |
| 95 | void barR10376675(int *x) { |
| 96 | int *pm; |
| 97 | if (nR10376675 * 2) { |
| 98 | int *pk = bazR10376675(); |
| 99 | pm = pk; //expected-warning {{never read}} |
| 100 | } |
| 101 | do { |
| 102 | *x = fooR10376675(); |
| 103 | } while (0); |
| 104 | } |
Ted Kremenek | 729aa06 | 2011-11-14 20:05:54 +0000 | [diff] [blame] | 105 | |
| 106 | // Test accesses to wide character strings doesn't break the analyzer. |
| 107 | typedef int wchar_t; |
| 108 | struct rdar10385775 { |
| 109 | wchar_t *name; |
| 110 | }; |
| 111 | void RDar10385775(struct rdar10385775* p) { |
| 112 | p->name = L"a"; |
| 113 | } |