diff options
author | Anna Zaks <ganna@apple.com> | 2013-02-07 23:05:43 +0000 |
---|---|---|
committer | Anna Zaks <ganna@apple.com> | 2013-02-07 23:05:43 +0000 |
commit | acdc13cb00591e2ab2b168c7924d7eb57fa4808e (patch) | |
tree | 2bb86597344e1dc645c2501fc028214b3f8bdd17 /clang/test/Analysis/malloc.c | |
parent | 7c1f408636d2d2cb2bc5890735d6cac1658dd28e (diff) | |
download | bcm5719-llvm-acdc13cb00591e2ab2b168c7924d7eb57fa4808e.tar.gz bcm5719-llvm-acdc13cb00591e2ab2b168c7924d7eb57fa4808e.zip |
[analyzer] Add pointer escape type param to checkPointerEscape callback
The checkPointerEscape callback previously did not specify how a
pointer escaped. This change includes an enum which describes the
different ways a pointer may escape. This enum is passed to the
checkPointerEscape callback when a pointer escapes. If the escape
is due to a function call, the call is passed. This changes
previous behavior where the call is passed as NULL if the escape
was due to indirectly invalidating the region the pointer referenced.
A patch by Branden Archer!
llvm-svn: 174677
Diffstat (limited to 'clang/test/Analysis/malloc.c')
-rw-r--r-- | clang/test/Analysis/malloc.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/clang/test/Analysis/malloc.c b/clang/test/Analysis/malloc.c index ed2d8e9d50a..9dc17e630fc 100644 --- a/clang/test/Analysis/malloc.c +++ b/clang/test/Analysis/malloc.c @@ -13,6 +13,7 @@ void *reallocf(void *ptr, size_t size); void *calloc(size_t nmemb, size_t size); char *strdup(const char *s); char *strndup(const char *s, size_t n); +int memcmp(const void *s1, const void *s2, size_t n); void myfoo(int *p); void myfooint(int p); @@ -1023,6 +1024,27 @@ char *testLeakWithinReturn(char *str) { return strdup(strdup(str)); // expected-warning{{leak}} } +void passConstPtr(const char * ptr); + +void testPassConstPointer() { + char * string = malloc(sizeof(char)*10); + passConstPtr(string); + return; // expected-warning {{leak}} +} + +void testPassConstPointerIndirectly() { + char *p = malloc(1); + p++; + memcmp(p, p, sizeof(&p)); + return; // expected-warning {{leak}} +} + +void testPassToSystemHeaderFunctionIndirectly() { + int *p = malloc(4); + p++; + fakeSystemHeaderCallInt(p); +} // expected-warning {{leak}} + // ---------------------------------------------------------------------------- // False negatives. @@ -1055,5 +1077,17 @@ void localStructTest() { pSt->memP = malloc(12); } // missing warning +void testPassConstPointerIndirectlyStruct() { + struct HasPtr hp; + hp.p = malloc(10); + memcmp(&hp, &hp, sizeof(hp)); + return; // missing leak +} + +void testPassToSystemHeaderFunctionIndirectlyStruct() { + SomeStruct ss; + ss.p = malloc(1); + fakeSystemHeaderCall(&ss); +} // missing leak |