Daniel Dunbar | d7d5f02 | 2009-03-24 02:24:46 +0000 | [diff] [blame] | 1 | // RUN: clang-cc -analyze -checker-cfref --analyzer-store=basic -analyzer-constraints=basic --verify -fblocks %s && |
Ted Kremenek | c037eac | 2009-07-10 00:41:58 +0000 | [diff] [blame] | 2 | // RUN: clang-cc -analyze -checker-cfref --analyzer-store=basic-old-cast -analyzer-constraints=basic --verify -fblocks %s && |
Ted Kremenek | 921109a | 2009-07-01 23:19:52 +0000 | [diff] [blame] | 3 | // RUN: clang-cc -analyze -checker-cfref --analyzer-store=basic -analyzer-constraints=range --verify -fblocks %s && |
Ted Kremenek | c037eac | 2009-07-10 00:41:58 +0000 | [diff] [blame] | 4 | // RUN: clang-cc -analyze -checker-cfref --analyzer-store=basic-old-cast -analyzer-constraints=range --verify -fblocks %s && |
Ted Kremenek | 921109a | 2009-07-01 23:19:52 +0000 | [diff] [blame] | 5 | // RUN: clang-cc -analyze -checker-cfref --analyzer-store=region -analyzer-constraints=basic --verify -fblocks %s && |
| 6 | // RUN: clang-cc -analyze -checker-cfref --analyzer-store=region -analyzer-constraints=range --verify -fblocks %s |
Ted Kremenek | 293769a | 2009-07-20 21:00:55 +0000 | [diff] [blame^] | 7 | // XFAIL |
Ted Kremenek | 2dabd42 | 2009-01-22 18:53:15 +0000 | [diff] [blame] | 8 | |
Ted Kremenek | f684d56 | 2009-03-05 18:08:28 +0000 | [diff] [blame] | 9 | typedef struct objc_selector *SEL; |
| 10 | typedef signed char BOOL; |
| 11 | typedef int NSInteger; |
| 12 | typedef unsigned int NSUInteger; |
| 13 | typedef struct _NSZone NSZone; |
Ted Kremenek | 5997888 | 2009-07-08 22:42:46 +0000 | [diff] [blame] | 14 | @class NSInvocation, NSArray, NSMethodSignature, NSCoder, NSString, NSEnumerator; |
Ted Kremenek | f684d56 | 2009-03-05 18:08:28 +0000 | [diff] [blame] | 15 | @protocol NSObject - (BOOL)isEqual:(id)object; @end |
| 16 | @protocol NSCopying - (id)copyWithZone:(NSZone *)zone; @end |
| 17 | @protocol NSMutableCopying - (id)mutableCopyWithZone:(NSZone *)zone; @end |
| 18 | @protocol NSCoding - (void)encodeWithCoder:(NSCoder *)aCoder; @end |
| 19 | @interface NSObject <NSObject> {} - (id)init; @end |
| 20 | extern id NSAllocateObject(Class aClass, NSUInteger extraBytes, NSZone *zone); |
| 21 | @interface NSString : NSObject <NSCopying, NSMutableCopying, NSCoding> |
| 22 | - (NSUInteger)length; |
| 23 | + (id)stringWithUTF8String:(const char *)nullTerminatedCString; |
| 24 | @end extern NSString * const NSBundleDidLoadNotification; |
| 25 | @interface NSAssertionHandler : NSObject {} |
| 26 | + (NSAssertionHandler *)currentHandler; |
| 27 | - (void)handleFailureInMethod:(SEL)selector object:(id)object file:(NSString *)fileName lineNumber:(NSInteger)line description:(NSString *)format,...; |
| 28 | @end |
| 29 | extern NSString * const NSConnectionReplyMode; |
Ted Kremenek | 693de5d | 2009-03-23 15:42:58 +0000 | [diff] [blame] | 30 | typedef float CGFloat; |
| 31 | typedef struct _NSPoint { |
| 32 | CGFloat x; |
| 33 | CGFloat y; |
| 34 | } NSPoint; |
| 35 | typedef struct _NSSize { |
| 36 | CGFloat width; |
| 37 | CGFloat height; |
| 38 | } NSSize; |
| 39 | typedef struct _NSRect { |
| 40 | NSPoint origin; |
| 41 | NSSize size; |
| 42 | } NSRect; |
Ted Kremenek | 9f67ede | 2008-10-01 05:05:46 +0000 | [diff] [blame] | 43 | |
| 44 | // Reduced test case from crash in <rdar://problem/6253157> |
Ted Kremenek | 9f67ede | 2008-10-01 05:05:46 +0000 | [diff] [blame] | 45 | @interface A @end |
| 46 | @implementation A |
| 47 | - (void)foo:(void (^)(NSObject *x))block { |
| 48 | if (!((block != ((void *)0)))) {} |
| 49 | } |
| 50 | @end |
| 51 | |
Ted Kremenek | 6dfe2f5 | 2008-10-18 22:20:20 +0000 | [diff] [blame] | 52 | // Reduced test case from crash in PR 2796; |
| 53 | // http://llvm.org/bugs/show_bug.cgi?id=2796 |
| 54 | |
| 55 | unsigned foo(unsigned x) { return __alignof__((x)) + sizeof(x); } |
Ted Kremenek | 9253b0f | 2008-10-20 23:14:31 +0000 | [diff] [blame] | 56 | |
| 57 | // Improvement to path-sensitivity involving compound assignments. |
| 58 | // Addresses false positive in <rdar://problem/6268365> |
| 59 | // |
| 60 | |
| 61 | unsigned r6268365Aux(); |
| 62 | |
| 63 | void r6268365() { |
| 64 | unsigned x = 0; |
| 65 | x &= r6268365Aux(); |
| 66 | unsigned j = 0; |
| 67 | |
| 68 | if (x == 0) ++j; |
| 69 | if (x == 0) x = x / j; // no-warning |
| 70 | } |
| 71 | |
Ted Kremenek | c13b6e2 | 2008-10-20 23:40:25 +0000 | [diff] [blame] | 72 | void divzeroassume(unsigned x, unsigned j) { |
| 73 | x /= j; |
| 74 | if (j == 0) x /= 0; // no-warning |
| 75 | if (j == 0) x /= j; // no-warning |
| 76 | if (j == 0) x = x / 0; // no-warning |
| 77 | } |
| 78 | |
| 79 | void divzeroassumeB(unsigned x, unsigned j) { |
| 80 | x = x / j; |
| 81 | if (j == 0) x /= 0; // no-warning |
| 82 | if (j == 0) x /= j; // no-warning |
| 83 | if (j == 0) x = x / 0; // no-warning |
| 84 | } |
| 85 | |
Ted Kremenek | 76dba7b | 2008-11-13 05:05:34 +0000 | [diff] [blame] | 86 | // InitListExpr processing |
| 87 | |
| 88 | typedef float __m128 __attribute__((__vector_size__(16), __may_alias__)); |
| 89 | __m128 return128() { |
Ted Kremenek | 062e2f9 | 2008-11-13 06:10:40 +0000 | [diff] [blame] | 90 | // This compound literal has a Vector type. We currently just |
| 91 | // return UnknownVal. |
Ted Kremenek | 76dba7b | 2008-11-13 05:05:34 +0000 | [diff] [blame] | 92 | return __extension__(__m128) { 0.0f, 0.0f, 0.0f, 0.0f }; |
| 93 | } |
| 94 | |
Ted Kremenek | 062e2f9 | 2008-11-13 06:10:40 +0000 | [diff] [blame] | 95 | typedef long long __v2di __attribute__ ((__vector_size__ (16))); |
| 96 | typedef long long __m128i __attribute__ ((__vector_size__ (16), __may_alias__)); |
| 97 | __m128i vec128i(long long __q1, long long __q0) { |
| 98 | // This compound literal returns true for both isVectorType() and |
| 99 | // isIntegerType(). |
| 100 | return __extension__ (__m128i)(__v2di){ __q0, __q1 }; |
| 101 | } |
| 102 | |
Ted Kremenek | 8322d6a | 2008-12-09 00:14:48 +0000 | [diff] [blame] | 103 | // Zero-sized VLAs. |
| 104 | void check_zero_sized_VLA(int x) { |
| 105 | if (x) |
| 106 | return; |
| 107 | |
Ted Kremenek | eaedfea | 2009-05-10 05:11:21 +0000 | [diff] [blame] | 108 | int vla[x]; // expected-warning{{Variable-length array 'vla' has zero elements (undefined behavior)}} |
Ted Kremenek | 159d248 | 2008-12-09 00:44:16 +0000 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | void check_uninit_sized_VLA() { |
| 112 | int x; |
Ted Kremenek | eaedfea | 2009-05-10 05:11:21 +0000 | [diff] [blame] | 113 | int vla[x]; // expected-warning{{Variable-length array 'vla' garbage value for array size}} |
Ted Kremenek | 8322d6a | 2008-12-09 00:14:48 +0000 | [diff] [blame] | 114 | } |
Ted Kremenek | 062e2f9 | 2008-11-13 06:10:40 +0000 | [diff] [blame] | 115 | |
Ted Kremenek | 55f7bcb | 2008-12-15 18:51:00 +0000 | [diff] [blame] | 116 | // sizeof(void) |
| 117 | // - Tests a regression reported in PR 3211: http://llvm.org/bugs/show_bug.cgi?id=3211 |
| 118 | void handle_sizeof_void(unsigned flag) { |
| 119 | int* p = 0; |
| 120 | |
| 121 | if (flag) { |
| 122 | if (sizeof(void) == 1) |
| 123 | return; |
| 124 | // Infeasible. |
| 125 | *p = 1; // no-warning |
| 126 | } |
| 127 | |
| 128 | void* q; |
| 129 | |
| 130 | if (!flag) { |
| 131 | if (sizeof(*q) == 1) |
| 132 | return; |
| 133 | // Infeasibe. |
| 134 | *p = 1; // no-warning |
| 135 | } |
| 136 | |
| 137 | // Infeasible. |
| 138 | *p = 1; // no-warning |
| 139 | } |
| 140 | |
Ted Kremenek | d76d47e | 2009-01-27 18:29:03 +0000 | [diff] [blame] | 141 | // PR 3422 |
| 142 | void pr3422_helper(char *p); |
| 143 | void pr3422() { |
| 144 | char buf[100]; |
| 145 | char *q = &buf[10]; |
| 146 | pr3422_helper(&q[1]); |
| 147 | } |
| 148 | |
Ted Kremenek | a3d1eb8 | 2009-02-14 05:55:08 +0000 | [diff] [blame] | 149 | // PR 3543 (handle empty statement expressions) |
| 150 | int pr_3543(void) { |
| 151 | ({}); |
| 152 | } |
| 153 | |
Ted Kremenek | 265a305 | 2009-02-24 02:23:11 +0000 | [diff] [blame] | 154 | // <rdar://problem/6611677> |
| 155 | // This test case test the use of a vector type within an array subscript |
| 156 | // expression. |
| 157 | typedef long long __a64vector __attribute__((__vector_size__(8))); |
| 158 | typedef long long __a128vector __attribute__((__vector_size__(16))); |
| 159 | static inline __a64vector __attribute__((__always_inline__, __nodebug__)) |
| 160 | my_test_mm_movepi64_pi64(__a128vector a) { |
| 161 | return (__a64vector)a[0]; |
| 162 | } |
| 163 | |
Ted Kremenek | f684d56 | 2009-03-05 18:08:28 +0000 | [diff] [blame] | 164 | // Test basic tracking of ivars associated with 'self'. |
| 165 | @interface SelfIvarTest : NSObject { |
| 166 | int flag; |
| 167 | } |
| 168 | - (void)test_self_tracking; |
| 169 | @end |
| 170 | |
| 171 | @implementation SelfIvarTest |
| 172 | - (void)test_self_tracking { |
| 173 | char *p = 0; |
| 174 | char c; |
| 175 | |
| 176 | if (flag) |
| 177 | p = "hello"; |
| 178 | |
| 179 | if (flag) |
| 180 | c = *p; // no-warning |
| 181 | } |
| 182 | @end |
Ted Kremenek | a3d1eb8 | 2009-02-14 05:55:08 +0000 | [diff] [blame] | 183 | |
Ted Kremenek | 7de20fe | 2009-03-11 02:29:48 +0000 | [diff] [blame] | 184 | // PR 3770 |
| 185 | char pr3770(int x) { |
| 186 | int y = x & 0x2; |
| 187 | char *p = 0; |
| 188 | if (y == 1) |
| 189 | p = "hello"; |
| 190 | |
| 191 | if (y == 1) |
| 192 | return p[0]; // no-warning |
| 193 | |
| 194 | return 'a'; |
| 195 | } |
| 196 | |
Ted Kremenek | 344d4c8 | 2009-03-11 18:17:16 +0000 | [diff] [blame] | 197 | // PR 3772 |
Ted Kremenek | fa6228d | 2009-03-11 02:52:39 +0000 | [diff] [blame] | 198 | // - We just want to test that this doesn't crash the analyzer. |
| 199 | typedef struct st ST; |
| 200 | struct st { char *name; }; |
| 201 | extern ST *Cur_Pu; |
| 202 | |
Ted Kremenek | 344d4c8 | 2009-03-11 18:17:16 +0000 | [diff] [blame] | 203 | void pr3772(void) |
Ted Kremenek | fa6228d | 2009-03-11 02:52:39 +0000 | [diff] [blame] | 204 | { |
| 205 | static ST *last_Cur_Pu; |
| 206 | if (last_Cur_Pu == Cur_Pu) { |
| 207 | return; |
| 208 | } |
| 209 | } |
| 210 | |
Ted Kremenek | 344d4c8 | 2009-03-11 18:17:16 +0000 | [diff] [blame] | 211 | // PR 3780 - This tests that StmtIterator isn't broken for VLAs in DeclGroups. |
| 212 | void pr3780(int sz) { typedef double MAT[sz][sz]; } |
Ted Kremenek | fa6228d | 2009-03-11 02:52:39 +0000 | [diff] [blame] | 213 | |
Ted Kremenek | ec099f1 | 2009-03-18 22:10:22 +0000 | [diff] [blame] | 214 | // <rdar://problem/6695527> - Test that we don't symbolicate doubles before |
| 215 | // we are ready to do something with them. |
| 216 | int rdar6695527(double x) { |
| 217 | if (!x) { return 0; } |
| 218 | return 1; |
| 219 | } |
Ted Kremenek | 693de5d | 2009-03-23 15:42:58 +0000 | [diff] [blame] | 220 | |
| 221 | // <rdar://problem/6708148> - Test that we properly invalidate structs |
| 222 | // passed-by-reference to a function. |
| 223 | void pr6708148_invalidate(NSRect *x); |
| 224 | void pr6708148_use(NSRect x); |
| 225 | void pr6708148_test(void) { |
| 226 | NSRect x; |
| 227 | pr6708148_invalidate(&x); |
| 228 | pr6708148_use(x); // no-warning |
| 229 | } |
| 230 | |
Ted Kremenek | b725232 | 2009-04-10 00:01:14 +0000 | [diff] [blame] | 231 | // Handle both kinds of noreturn attributes for pruning paths. |
| 232 | void rdar_6777003_noret() __attribute__((noreturn)); |
| 233 | void rdar_6777003_analyzer_noret() __attribute__((analyzer_noreturn)); |
| 234 | |
| 235 | void rdar_6777003(int x) { |
| 236 | int *p = 0; |
| 237 | |
| 238 | if (x == 1) { |
| 239 | rdar_6777003_noret(); |
| 240 | *p = 1; // no-warning; |
| 241 | } |
| 242 | |
| 243 | if (x == 2) { |
| 244 | rdar_6777003_analyzer_noret(); |
| 245 | *p = 1; // no-warning; |
| 246 | } |
| 247 | |
| 248 | *p = 1; // expected-warning{{Dereference of null pointer}} |
| 249 | } |
| 250 | |
Ted Kremenek | af48fdd | 2009-04-21 22:38:05 +0000 | [diff] [blame] | 251 | // For pointer arithmetic, --/++ should be treated as preserving non-nullness, |
| 252 | // regardless of how well the underlying StoreManager reasons about pointer |
| 253 | // arithmetic. |
| 254 | // <rdar://problem/6777209> |
Ted Kremenek | af48fdd | 2009-04-21 22:38:05 +0000 | [diff] [blame] | 255 | void rdar_6777209(char *p) { |
| 256 | if (p == 0) |
| 257 | return; |
| 258 | |
| 259 | ++p; |
| 260 | |
| 261 | // This branch should always be infeasible. |
| 262 | if (p == 0) |
| 263 | *p = 'c'; // no-warning |
| 264 | } |
Ted Kremenek | b3cfd58 | 2009-04-23 17:49:43 +0000 | [diff] [blame] | 265 | |
| 266 | // PR 4033. A symbolic 'void *' pointer can be used as the address for a |
| 267 | // computed goto. |
| 268 | typedef void *Opcode; |
| 269 | Opcode pr_4033_getOpcode(); |
| 270 | void pr_4033(void) { |
| 271 | next_opcode: |
| 272 | { |
| 273 | Opcode op = pr_4033_getOpcode(); |
| 274 | if (op) goto *op; |
| 275 | } |
| 276 | } |
| 277 | |
Ted Kremenek | 956a37d | 2009-05-01 23:35:18 +0000 | [diff] [blame] | 278 | // Test invalidating pointers-to-pointers with slightly different types. This |
| 279 | // example came from a recent false positive due to a regression where the |
| 280 | // branch condition was falsely reported as being uninitialized. |
| 281 | void invalidate_by_ref(char **x); |
| 282 | int test_invalidate_by_ref() { |
| 283 | unsigned short y; |
| 284 | invalidate_by_ref((char**) &y); |
| 285 | if (y) // no-warning |
| 286 | return 1; |
| 287 | return 0; |
| 288 | } |
| 289 | |
Ted Kremenek | ed47fc6 | 2009-07-03 00:10:50 +0000 | [diff] [blame] | 290 | // Test for <rdar://problem/7027684>. This just tests that the CFG is |
| 291 | // constructed correctly. Previously, the successor block of the entrance |
| 292 | // was the block containing the merge for '?', which would trigger an |
| 293 | // assertion failure. |
| 294 | int rdar_7027684_aux(); |
| 295 | int rdar_7027684_aux_2() __attribute__((noreturn)); |
| 296 | void rdar_7027684(int x, int y) { |
| 297 | {}; // this empty compound statement is critical. |
| 298 | (rdar_7027684_aux() ? rdar_7027684_aux_2() : (void) 0); |
| 299 | } |
| 300 | |
Ted Kremenek | 411af40 | 2009-07-06 22:23:45 +0000 | [diff] [blame] | 301 | // Test that we handle casts of string literals to arbitrary types. |
| 302 | unsigned const char *string_literal_test1() { |
| 303 | return (const unsigned char*) "hello"; |
| 304 | } |
| 305 | |
| 306 | const float *string_literal_test2() { |
| 307 | return (const float*) "hello"; |
| 308 | } |
| 309 | |
Ted Kremenek | 169077d | 2009-07-06 23:47:19 +0000 | [diff] [blame] | 310 | // Test that we handle casts *from* incomplete struct types. |
| 311 | extern const struct _FooAssertStruct _cmd; |
| 312 | void test_cast_from_incomplete_struct_aux(volatile const void *x); |
| 313 | void test_cast_from_incomplete_struct() { |
| 314 | test_cast_from_incomplete_struct_aux(&_cmd); |
| 315 | } |
Ted Kremenek | ed47fc6 | 2009-07-03 00:10:50 +0000 | [diff] [blame] | 316 | |
Ted Kremenek | 5997888 | 2009-07-08 22:42:46 +0000 | [diff] [blame] | 317 | // Test for <rdar://problem/7034511> |
| 318 | // "ValueManager::makeIntVal(uint64_t X, QualType T) should return a 'Loc' |
| 319 | // when 'T' is a pointer" |
| 320 | // |
| 321 | // Previously this case would crash. |
| 322 | void test_rdar_7034511(NSArray *y) { |
| 323 | NSObject *x; |
| 324 | for (x in y) {} |
| 325 | if (x == ((void*) 0)) {} |
| 326 | } |
| 327 | |
Ted Kremenek | 8d344ae | 2009-07-10 21:24:45 +0000 | [diff] [blame] | 328 | // Handle casts of function pointers (CodeTextRegions) to arbitrary pointer |
| 329 | // types. This was previously causing a crash in CastRegion. |
| 330 | void handle_funcptr_voidptr_casts() { |
Ted Kremenek | 3f9811b | 2009-07-10 21:11:16 +0000 | [diff] [blame] | 331 | void **ptr; |
| 332 | typedef void *PVOID; |
Ted Kremenek | 8d344ae | 2009-07-10 21:24:45 +0000 | [diff] [blame] | 333 | typedef void *PCHAR; |
Ted Kremenek | 3f9811b | 2009-07-10 21:11:16 +0000 | [diff] [blame] | 334 | typedef long INT_PTR, *PINT_PTR; |
| 335 | typedef INT_PTR (*FARPROC)(); |
Ted Kremenek | 8d344ae | 2009-07-10 21:24:45 +0000 | [diff] [blame] | 336 | FARPROC handle_funcptr_voidptr_casts_aux(); |
| 337 | PVOID handle_funcptr_voidptr_casts_aux_2(PVOID volatile *x); |
| 338 | PVOID handle_funcptr_voidptr_casts_aux_3(PCHAR volatile *x); |
Ted Kremenek | 3f9811b | 2009-07-10 21:11:16 +0000 | [diff] [blame] | 339 | |
Ted Kremenek | 8d344ae | 2009-07-10 21:24:45 +0000 | [diff] [blame] | 340 | ptr = (void**) handle_funcptr_voidptr_casts_aux(); |
| 341 | handle_funcptr_voidptr_casts_aux_2(ptr); |
| 342 | handle_funcptr_voidptr_casts_aux_3(ptr); |
Ted Kremenek | 3f9811b | 2009-07-10 21:11:16 +0000 | [diff] [blame] | 343 | } |
| 344 | |
Ted Kremenek | 31ef2b6 | 2009-07-10 21:43:30 +0000 | [diff] [blame] | 345 | // RegionStore::Retrieve previously crashed on this example. This example |
| 346 | // was previously in the test file 'xfail_regionstore_wine_crash.c'. |
| 347 | void testA() { |
| 348 | long x = 0; |
| 349 | char *y = (char *) &x; |
| 350 | if (!*y) |
| 351 | return; |
| 352 | } |
| 353 | |
Ted Kremenek | 43d74a5 | 2009-07-11 04:38:49 +0000 | [diff] [blame] | 354 | // RegionStoreManager previously crashed on this example. The problem is that |
| 355 | // the value bound to the field of b->grue after the call to testB_aux is |
| 356 | // a symbolic region. The second '*__gruep__' involves performing a load |
| 357 | // from a 'int*' that really is a 'void**'. The loaded location must be |
| 358 | // implicitly converted to an integer that wraps a location. Previosly we would |
| 359 | // get a crash here due to an assertion failure. |
| 360 | typedef struct _BStruct { void *grue; } BStruct; |
| 361 | void testB_aux(void *ptr); |
| 362 | void testB(BStruct *b) { |
| 363 | { |
| 364 | int *__gruep__ = ((int *)&((b)->grue)); |
| 365 | int __gruev__ = *__gruep__; |
| 366 | testB_aux(__gruep__); |
| 367 | } |
| 368 | { |
| 369 | int *__gruep__ = ((int *)&((b)->grue)); |
| 370 | int __gruev__ = *__gruep__; |
| 371 | if (~0 != __gruev__) {} |
| 372 | } |
| 373 | } |
| 374 | |
Ted Kremenek | 54ca9b1 | 2009-07-13 21:55:12 +0000 | [diff] [blame] | 375 | void test_trivial_symbolic_comparison(int *x) { |
| 376 | int test_trivial_symbolic_comparison_aux(); |
| 377 | int a = test_trivial_symbolic_comparison_aux(); |
| 378 | int b = a; |
| 379 | if (a != b) { |
| 380 | int *p = 0; |
| 381 | *p = 0xDEADBEEF; // no-warning |
| 382 | } |
| 383 | |
| 384 | a = a == 1; |
| 385 | b = b == 1; |
| 386 | if (a != b) { |
| 387 | int *p = 0; |
| 388 | *p = 0xDEADBEEF; // no-warning |
| 389 | } |
| 390 | } |
| 391 | |
Ted Kremenek | fde2efe | 2009-07-15 22:09:25 +0000 | [diff] [blame] | 392 | // Test for: |
| 393 | // <rdar://problem/7062158> false positive null dereference due to |
| 394 | // BasicStoreManager not tracking *static* globals |
| 395 | // |
| 396 | // This just tests the proper tracking of symbolic values for globals (both |
| 397 | // static and non-static). |
| 398 | // |
| 399 | static int* x_rdar_7062158; |
| 400 | void rdar_7062158() { |
| 401 | int *current = x_rdar_7062158; |
| 402 | if (current == x_rdar_7062158) |
| 403 | return; |
| 404 | |
| 405 | int *p = 0; |
| 406 | *p = 0xDEADBEEF; // no-warning |
| 407 | } |
| 408 | |
| 409 | int* x_rdar_7062158_2; |
| 410 | void rdar_7062158_2() { |
| 411 | int *current = x_rdar_7062158_2; |
| 412 | if (current == x_rdar_7062158_2) |
| 413 | return; |
| 414 | |
| 415 | int *p = 0; |
| 416 | *p = 0xDEADBEEF; // no-warning |
| 417 | } |
| 418 | |
Ted Kremenek | 4653739 | 2009-07-16 01:33:37 +0000 | [diff] [blame] | 419 | // This test reproduces a case for a crash when analyzing ClamAV using |
| 420 | // RegionStoreManager (the crash doesn't exhibit in BasicStoreManager because |
| 421 | // it isn't doing anything smart about arrays). The problem is that on the |
| 422 | // second line, 'p = &p[i]', p is assigned an ElementRegion whose index |
| 423 | // is a 16-bit integer. On the third line, a new ElementRegion is created |
| 424 | // based on the previous region, but there the region uses a 32-bit integer, |
| 425 | // resulting in a clash of values (an assertion failure at best). We resolve |
| 426 | // this problem by implicitly converting index values to 'int' when the |
| 427 | // ElementRegion is created. |
| 428 | unsigned char test_array_index_bitwidth(const unsigned char *p) { |
| 429 | unsigned short i = 0; |
| 430 | for (i = 0; i < 2; i++) p = &p[i]; |
| 431 | return p[i+1]; |
| 432 | } |
| 433 | |
Ted Kremenek | 63b9cfe | 2009-07-18 06:27:51 +0000 | [diff] [blame] | 434 | // This case tests that CastRegion handles casts involving BlockPointerTypes. |
| 435 | // It should not crash. |
| 436 | void test_block_cast() { |
| 437 | id test_block_cast_aux(); |
| 438 | (void (^)(void *))test_block_cast_aux(); // expected-warning{{expression result unused}} |
| 439 | } |
| 440 | |
Ted Kremenek | 293769a | 2009-07-20 21:00:55 +0000 | [diff] [blame^] | 441 | // ** THIS TEST FAILS ** |
| 442 | // Test comparison of 'id' instance variable to a null void* constant after |
| 443 | // performing an OSAtomicCompareAndSwap32Barrier. |
| 444 | // This previously was a crash in RegionStoreManager. |
| 445 | @interface TestIdNull { |
| 446 | id x; |
| 447 | } |
| 448 | -(int)foo; |
| 449 | @end |
| 450 | @implementation TestIdNull |
| 451 | -(int)foo { |
| 452 | OSAtomicCompareAndSwap32Barrier(0, (signed)2, (signed*)&x); |
| 453 | if (x == (void*) 0) { return 0; } |
| 454 | return 1; |
| 455 | } |
| 456 | @end |
| 457 | |
| 458 | |
| 459 | |