rdar-6541136-region.c revision 58e689fead1490611bcd114fb707bfc08a12049e
1d7d5f0223bd30dfd618762349c6209dd1d5ea3e6Daniel Dunbar// RUN: clang-cc -verify -analyze -checker-cfref -analyzer-store=region %s 214553abd17d303b0b310b3ab1523eb0d30d8121cTed Kremenek 314553abd17d303b0b310b3ab1523eb0d30d8121cTed Kremenekstruct tea_cheese { unsigned magic; }; 414553abd17d303b0b310b3ab1523eb0d30d8121cTed Kremenektypedef struct tea_cheese kernel_tea_cheese_t; 514553abd17d303b0b310b3ab1523eb0d30d8121cTed Kremenekextern kernel_tea_cheese_t _wonky_gesticulate_cheese; 614553abd17d303b0b310b3ab1523eb0d30d8121cTed Kremenek 714553abd17d303b0b310b3ab1523eb0d30d8121cTed Kremenek// This test case exercises the ElementRegion::getRValueType() logic. 814553abd17d303b0b310b3ab1523eb0d30d8121cTed Kremenek 914553abd17d303b0b310b3ab1523eb0d30d8121cTed Kremenek 1014553abd17d303b0b310b3ab1523eb0d30d8121cTed Kremenekvoid foo( void ) 1114553abd17d303b0b310b3ab1523eb0d30d8121cTed Kremenek{ 1214553abd17d303b0b310b3ab1523eb0d30d8121cTed Kremenek kernel_tea_cheese_t *wonky = &_wonky_gesticulate_cheese; 1314553abd17d303b0b310b3ab1523eb0d30d8121cTed Kremenek struct load_wine *cmd = (void*) &wonky[1]; 1414553abd17d303b0b310b3ab1523eb0d30d8121cTed Kremenek cmd = cmd; 1514553abd17d303b0b310b3ab1523eb0d30d8121cTed Kremenek char *p = (void*) &wonky[1]; 1658e689fead1490611bcd114fb707bfc08a12049eZhongxing Xu //*p = 1; // this is also an out-of-bound access. 17ccb161603c3c280c378e6701986e9f3646898277Zhongxing Xu kernel_tea_cheese_t *q = &wonky[1]; 1839abcdf1c7dfc4fd2bda57416812672830400c9eTed Kremenek // This test case tests both the RegionStore logic (doesn't crash) and 1939abcdf1c7dfc4fd2bda57416812672830400c9eTed Kremenek // the out-of-bounds checking. We don't expect the warning for now since 2039abcdf1c7dfc4fd2bda57416812672830400c9eTed Kremenek // out-of-bound checking is temporarily disabled. 2158e689fead1490611bcd114fb707bfc08a12049eZhongxing Xu kernel_tea_cheese_t r = *q; // expected-warning{{Access out-of-bound array element (buffer overflow)}} 2214553abd17d303b0b310b3ab1523eb0d30d8121cTed Kremenek} 23