diff options
author | Anton Yartsev <anton.yartsev@gmail.com> | 2016-12-25 00:57:51 +0000 |
---|---|---|
committer | Anton Yartsev <anton.yartsev@gmail.com> | 2016-12-25 00:57:51 +0000 |
commit | 5ac3720620849a28e6d6eddd20e791650c53b12d (patch) | |
tree | 64e93ff0e59fa82124eb3a6712d2db3825f577eb /clang/test | |
parent | a7b624ec6a1f8cdfdffcaff270e15a70989a3ace (diff) | |
download | bcm5719-llvm-5ac3720620849a28e6d6eddd20e791650c53b12d.tar.gz bcm5719-llvm-5ac3720620849a28e6d6eddd20e791650c53b12d.zip |
Fix for PR15623 (corrected r290413 reverted at 290415). The patch eliminates unwanted ProgramState checker data propagation from an operand of the logical operation to operation result.
The patch also simplifies an assume of a constraint of the form: "(exp comparison_op expr) != 0" to true into an assume of "exp comparison_op expr" to true. (And similarly, an assume of the form "(exp comparison_op expr) == 0" to true as an assume of exp comparison_op expr to false.) which improves precision overall.
https://reviews.llvm.org/D22862
llvm-svn: 290505
Diffstat (limited to 'clang/test')
-rw-r--r-- | clang/test/Analysis/malloc.c | 11 | ||||
-rw-r--r-- | clang/test/Analysis/misc-ps.c | 10 |
2 files changed, 21 insertions, 0 deletions
diff --git a/clang/test/Analysis/malloc.c b/clang/test/Analysis/malloc.c index 51e2cd60432..d5bc6571e42 100644 --- a/clang/test/Analysis/malloc.c +++ b/clang/test/Analysis/malloc.c @@ -1763,6 +1763,17 @@ void testConstEscapeThroughAnotherField() { constEscape(&(s.x)); // could free s->p! } // no-warning +// PR15623 +int testNoCheckerDataPropogationFromLogicalOpOperandToOpResult(void) { + char *param = malloc(10); + char *value = malloc(10); + int ok = (param && value); + free(param); + free(value); + // Previously we ended up with 'Use of memory after it is freed' on return. + return ok; // no warning +} + // ---------------------------------------------------------------------------- // False negatives. diff --git a/clang/test/Analysis/misc-ps.c b/clang/test/Analysis/misc-ps.c index 01cad1549cd..ad65437e4c1 100644 --- a/clang/test/Analysis/misc-ps.c +++ b/clang/test/Analysis/misc-ps.c @@ -191,3 +191,13 @@ static void PR16131(int x) { clang_analyzer_eval(*ip == 42); // expected-warning{{TRUE}} clang_analyzer_eval(*(int *)&v == 42); // expected-warning{{TRUE}} } + +// PR15623: Currently the analyzer doesn't handle symbolic expressions of the +// form "(exp comparison_op expr) != 0" very well. We perform a simplification +// translating an assume of a constraint of the form "(exp comparison_op expr) +// != 0" to true into an assume of "exp comparison_op expr" to true. +void PR15623(int n) { + if ((n == 0) != 0) { + clang_analyzer_eval(n == 0); // expected-warning{{TRUE}} + } +} |