diff options
| author | Ted Kremenek <kremenek@apple.com> | 2010-01-08 18:54:04 +0000 |
|---|---|---|
| committer | Ted Kremenek <kremenek@apple.com> | 2010-01-08 18:54:04 +0000 |
| commit | b92304b42f7f7b9b294d9e7dd7ab96002dff5b97 (patch) | |
| tree | f832e4e4ce978dd6d3f74a8b47eb1a8ad7b48da1 /clang/test | |
| parent | af07fbe210b4a36cf19d213a4edd8a7e7fca0842 (diff) | |
| download | bcm5719-llvm-b92304b42f7f7b9b294d9e7dd7ab96002dff5b97.tar.gz bcm5719-llvm-b92304b42f7f7b9b294d9e7dd7ab96002dff5b97.zip | |
Fix handling in GRExprEngine of 'default' branch in switch statements
when the default case is winnowed down to be infeasible. When all
cases were ruled out (and the analysis state for the default case
would be infeasible) we would still consider the default case
possible. This fixes PR 5969.
llvm-svn: 93017
Diffstat (limited to 'clang/test')
| -rw-r--r-- | clang/test/Analysis/misc-ps-ranges.m | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/clang/test/Analysis/misc-ps-ranges.m b/clang/test/Analysis/misc-ps-ranges.m index 760b4d74335..df7e97c4673 100644 --- a/clang/test/Analysis/misc-ps-ranges.m +++ b/clang/test/Analysis/misc-ps-ranges.m @@ -21,3 +21,40 @@ int main(int argc, char* argv[]) { return *p; // no-warning } + +// PR 5969: the comparison of argc < 3 || argc > 4 should constraint the switch +// statement from having the 'default' branch taken. This previously reported a false +// positive with the use of 'v'. + +int pr5969(int argc, char *argv[]) { + + int v; + + if ((argc < 3) || (argc > 4)) return 0; + + switch(argc) { + case 3: + v = 33; + break; + case 4: + v = 44; + break; + } + + return v; // no-warning +} + +int pr5969_positive(int argc, char *argv[]) { + + int v; + + if ((argc < 3) || (argc > 4)) return 0; + + switch(argc) { + case 3: + v = 33; + break; + } + + return v; // expected-warning{{Undefined or garbage value returned to caller}} +} |

