[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!
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174677 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/test/Analysis/malloc.c b/test/Analysis/malloc.c
index ed2d8e9..9dc17e6 100644
--- a/test/Analysis/malloc.c
+++ b/test/Analysis/malloc.c
@@ -13,6 +13,7 @@
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 @@
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 @@
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