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 | 3563fde6a02c2a75d0b4ba629d80c5511056a688 (patch) | |
tree | aca126926b2c9e50bd63aa6239cfcfe4205147e7 /clang/test/Analysis/malloc.c | |
parent | 5fb2e4dabebbda722858307aa1197db571cad73f (diff) | |
download | bcm5719-llvm-3563fde6a02c2a75d0b4ba629d80c5511056a688.tar.gz bcm5719-llvm-3563fde6a02c2a75d0b4ba629d80c5511056a688.zip |
[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.
llvm-svn: 158136
Diffstat (limited to 'clang/test/Analysis/malloc.c')
-rw-r--r-- | clang/test/Analysis/malloc.c | 51 |
1 files changed, 47 insertions, 4 deletions
diff --git a/clang/test/Analysis/malloc.c b/clang/test/Analysis/malloc.c index d0d095b1d4c..bdbd96e2be4 100644 --- a/clang/test/Analysis/malloc.c +++ b/clang/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. |