diff options
author | Anna Zaks <ganna@apple.com> | 2012-06-07 03:57:32 +0000 |
---|---|---|
committer | Anna Zaks <ganna@apple.com> | 2012-06-07 03:57:32 +0000 |
commit | e17fdb2d5dbf0ffefd417587003eebbe5baf5984 (patch) | |
tree | 0cd9585d53661ebde4fa7f2f22a991802284b0cf /test/Analysis/malloc.c | |
parent | 826eac59e4b107973ed1c5a761ad8785aa1bcde4 (diff) |
[analyzer] Anti-aliasing: different heap allocations do not alias
Add a concept of symbolic memory region belonging to heap memory space.
When comparing symbolic regions allocated on the heap, assume that they
do not alias.
Use symbolic heap region to suppress a common false positive pattern in
the malloc checker, in code that relies on malloc not returning the
memory aliased to other malloc allocations, stack.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@158136 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Analysis/malloc.c')
-rw-r--r-- | test/Analysis/malloc.c | 51 |
1 files changed, 47 insertions, 4 deletions
diff --git a/test/Analysis/malloc.c b/test/Analysis/malloc.c index d0d095b1d4..bdbd96e2be 100644 --- a/test/Analysis/malloc.c +++ b/test/Analysis/malloc.c @@ -839,10 +839,8 @@ int fPtr(unsigned cond, int x) { return (cond ? mySub : myAdd)(x, x); } -// ---------------------------------------------------------------------------- -// Below are the known false positives. +// Test anti-aliasing. -// TODO: There should be no warning here. This one might be difficult to get rid of. void dependsOnValueOfPtr(int *g, unsigned f) { int *p; @@ -855,10 +853,55 @@ void dependsOnValueOfPtr(int *g, unsigned f) { if (p != g) free(p); else - return; // expected-warning{{Memory is never released; potential leak}} + return; // no warning return; } +int CMPRegionHeapToStack() { + int x = 0; + int *x1 = malloc(8); + int *x2 = &x; + if (x1 == x2) + return 5/x; // expected-warning{{This statement is never executed}} + free(x1); + return x; +} + +int CMPRegionHeapToHeap2() { + int x = 0; + int *x1 = malloc(8); + int *x2 = malloc(8); + int *x4 = x1; + int *x5 = x2; + if (x4 == x5) + return 5/x; // expected-warning{{This statement is never executed}} + free(x1); + free(x2); + return x; +} + +int CMPRegionHeapToHeap() { + int x = 0; + int *x1 = malloc(8); + int *x4 = x1; + if (x1 == x4) { + free(x1); + return 5/x; // expected-warning{{Division by zero}} + } + return x;// expected-warning{{This statement is never executed}} +} + +int HeapAssignment() { + int m = 0; + int *x = malloc(4); + int *y = x; + *x = 5; + if (*x != *y) + return 5/m; // expected-warning{{This statement is never executed}} + free(x); + return 0; +} + // ---------------------------------------------------------------------------- // False negatives. |