Ted Kremenek | 8382cf5 | 2009-11-13 18:46:29 +0000 | [diff] [blame] | 1 | // RUN: clang-cc -verify -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region %s |
Ted Kremenek | 14553ab | 2009-01-30 00:08:43 +0000 | [diff] [blame] | 2 | |
| 3 | struct tea_cheese { unsigned magic; }; |
| 4 | typedef struct tea_cheese kernel_tea_cheese_t; |
| 5 | extern kernel_tea_cheese_t _wonky_gesticulate_cheese; |
| 6 | |
| 7 | // This test case exercises the ElementRegion::getRValueType() logic. |
| 8 | |
Ted Kremenek | ab6d622 | 2009-11-11 17:17:06 +0000 | [diff] [blame] | 9 | void test1( void ) { |
Ted Kremenek | 14553ab | 2009-01-30 00:08:43 +0000 | [diff] [blame] | 10 | kernel_tea_cheese_t *wonky = &_wonky_gesticulate_cheese; |
| 11 | struct load_wine *cmd = (void*) &wonky[1]; |
| 12 | cmd = cmd; |
| 13 | char *p = (void*) &wonky[1]; |
Zhongxing Xu | ccb1616 | 2009-05-06 08:08:27 +0000 | [diff] [blame] | 14 | kernel_tea_cheese_t *q = &wonky[1]; |
Ted Kremenek | 39abcdf | 2009-08-01 05:59:39 +0000 | [diff] [blame] | 15 | // This test case tests both the RegionStore logic (doesn't crash) and |
| 16 | // the out-of-bounds checking. We don't expect the warning for now since |
| 17 | // out-of-bound checking is temporarily disabled. |
Zhongxing Xu | 58e689f | 2009-11-11 12:33:27 +0000 | [diff] [blame] | 18 | kernel_tea_cheese_t r = *q; // expected-warning{{Access out-of-bound array element (buffer overflow)}} |
Ted Kremenek | 14553ab | 2009-01-30 00:08:43 +0000 | [diff] [blame] | 19 | } |
Ted Kremenek | ab6d622 | 2009-11-11 17:17:06 +0000 | [diff] [blame] | 20 | |
| 21 | void test1_b( void ) { |
| 22 | kernel_tea_cheese_t *wonky = &_wonky_gesticulate_cheese; |
| 23 | struct load_wine *cmd = (void*) &wonky[1]; |
| 24 | cmd = cmd; |
| 25 | char *p = (void*) &wonky[1]; |
| 26 | *p = 1; // expected-warning{{Access out-of-bound array element (buffer overflow)}} |
| 27 | } |