Chris Lattner | ae0ee03 | 2008-12-04 23:20:07 +0000 | [diff] [blame] | 1 | // RUN: clang -checker-cfref --verify -fblocks %s |
Ted Kremenek | 9f67ede | 2008-10-01 05:05:46 +0000 | [diff] [blame] | 2 | |
| 3 | // Reduced test case from crash in <rdar://problem/6253157> |
| 4 | @class NSObject; |
| 5 | @interface A @end |
| 6 | @implementation A |
| 7 | - (void)foo:(void (^)(NSObject *x))block { |
| 8 | if (!((block != ((void *)0)))) {} |
| 9 | } |
| 10 | @end |
| 11 | |
Ted Kremenek | 6dfe2f5 | 2008-10-18 22:20:20 +0000 | [diff] [blame] | 12 | // Reduced test case from crash in PR 2796; |
| 13 | // http://llvm.org/bugs/show_bug.cgi?id=2796 |
| 14 | |
| 15 | unsigned foo(unsigned x) { return __alignof__((x)) + sizeof(x); } |
Ted Kremenek | 9253b0f | 2008-10-20 23:14:31 +0000 | [diff] [blame] | 16 | |
| 17 | // Improvement to path-sensitivity involving compound assignments. |
| 18 | // Addresses false positive in <rdar://problem/6268365> |
| 19 | // |
| 20 | |
| 21 | unsigned r6268365Aux(); |
| 22 | |
| 23 | void r6268365() { |
| 24 | unsigned x = 0; |
| 25 | x &= r6268365Aux(); |
| 26 | unsigned j = 0; |
| 27 | |
| 28 | if (x == 0) ++j; |
| 29 | if (x == 0) x = x / j; // no-warning |
| 30 | } |
| 31 | |
Ted Kremenek | c13b6e2 | 2008-10-20 23:40:25 +0000 | [diff] [blame] | 32 | void divzeroassume(unsigned x, unsigned j) { |
| 33 | x /= j; |
| 34 | if (j == 0) x /= 0; // no-warning |
| 35 | if (j == 0) x /= j; // no-warning |
| 36 | if (j == 0) x = x / 0; // no-warning |
| 37 | } |
| 38 | |
| 39 | void divzeroassumeB(unsigned x, unsigned j) { |
| 40 | x = x / j; |
| 41 | if (j == 0) x /= 0; // no-warning |
| 42 | if (j == 0) x /= j; // no-warning |
| 43 | if (j == 0) x = x / 0; // no-warning |
| 44 | } |
| 45 | |
Ted Kremenek | 5b2316a | 2008-10-25 20:09:21 +0000 | [diff] [blame] | 46 | // PR 2948 (testcase; crash on VisitLValue for union types) |
| 47 | // http://llvm.org/bugs/show_bug.cgi?id=2948 |
| 48 | |
| 49 | void checkaccess_union() { |
| 50 | int ret = 0, status; |
| 51 | if (((((__extension__ (((union { |
| 52 | __typeof (status) __in; int __i;} |
| 53 | ) |
| 54 | { |
| 55 | .__in = (status)} |
| 56 | ).__i))) & 0xff00) >> 8) == 1) |
| 57 | ret = 1; |
| 58 | } |
Ted Kremenek | 76dba7b | 2008-11-13 05:05:34 +0000 | [diff] [blame] | 59 | |
| 60 | // InitListExpr processing |
| 61 | |
| 62 | typedef float __m128 __attribute__((__vector_size__(16), __may_alias__)); |
| 63 | __m128 return128() { |
Ted Kremenek | 062e2f9 | 2008-11-13 06:10:40 +0000 | [diff] [blame] | 64 | // This compound literal has a Vector type. We currently just |
| 65 | // return UnknownVal. |
Ted Kremenek | 76dba7b | 2008-11-13 05:05:34 +0000 | [diff] [blame] | 66 | return __extension__(__m128) { 0.0f, 0.0f, 0.0f, 0.0f }; |
| 67 | } |
| 68 | |
Ted Kremenek | 062e2f9 | 2008-11-13 06:10:40 +0000 | [diff] [blame] | 69 | typedef long long __v2di __attribute__ ((__vector_size__ (16))); |
| 70 | typedef long long __m128i __attribute__ ((__vector_size__ (16), __may_alias__)); |
| 71 | __m128i vec128i(long long __q1, long long __q0) { |
| 72 | // This compound literal returns true for both isVectorType() and |
| 73 | // isIntegerType(). |
| 74 | return __extension__ (__m128i)(__v2di){ __q0, __q1 }; |
| 75 | } |
| 76 | |
Ted Kremenek | 8322d6a | 2008-12-09 00:14:48 +0000 | [diff] [blame] | 77 | // Zero-sized VLAs. |
| 78 | void check_zero_sized_VLA(int x) { |
| 79 | if (x) |
| 80 | return; |
| 81 | |
Ted Kremenek | 159d248 | 2008-12-09 00:44:16 +0000 | [diff] [blame^] | 82 | int vla[x]; // expected-warning{{VLAs with no elements have undefined behavior}} |
| 83 | } |
| 84 | |
| 85 | void check_uninit_sized_VLA() { |
| 86 | int x; |
| 87 | 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.}} |
Ted Kremenek | 8322d6a | 2008-12-09 00:14:48 +0000 | [diff] [blame] | 88 | } |
Ted Kremenek | 062e2f9 | 2008-11-13 06:10:40 +0000 | [diff] [blame] | 89 | |