CHECKER: Track '<', '>', etc. relationships between symbolic values
| Bugzilla Link | 2306 |
| Resolution | DUPLICATE |
| Resolved on | Dec 23, 2018 05:51 |
| Version | unspecified |
| OS | Linux |
| Blocks | llvm/llvm-bugzilla-archive#4272 llvm/llvm-bugzilla-archive#5628 |
| Attachments | checker html report |
| CC | @tkremenek,@haoNoQ |
Extended Description
Using SVN r50942:
/home/edwin/llvm-svn/llvm/tools/clang/utils/ccc-analyzer -c path_sens.c path_sens.c ANALYZE: path_sens.c foo path_sens.c:10:11: warning: [CHECKER] Dereference of null pointer. return *bar; ^~~ 1 diagnostic generated.
int foo(int left, int right) { int x=5; int *bar = 0; while(left<=right) { left++; bar = &x; } if(left<=right) { return *bar; } return 0; }
See the attached html report, it says that the while() condition is false, and then the if() condition is true. That can't happen, after the while (left<=right) is always false, hence the if is never entered.
mentioned in issue llvm/llvm-bugzilla-archive#7770
mentioned in issue llvm/llvm-bugzilla-archive#7494
mentioned in issue llvm/llvm-bugzilla-archive#5628
mentioned in issue llvm/llvm-bugzilla-archive#4272
mentioned in issue llvm/llvm-bugzilla-archive#40145
Duping to the constraint solver umbrella.
*** This bug has been marked as a duplicate of bug llvm/llvm-bugzilla-archive#40145 ***
*** Bug llvm/llvm-bugzilla-archive#7770 has been marked as a duplicate of this bug. ***
*** Bug llvm/llvm-bugzilla-archive#7494 has been marked as a duplicate of this bug. ***
*** Bug llvm/llvm-project#2677 has been marked as a duplicate of this bug. ***
The analyzer treats the function parameters "left" and "right" as symbolic values. Currently the analyzer doesn't support tracking relational constraints (e.g., left <= right) between symbolic values. If you change the code to have "==" instead of "<=" then things will go as you expect. This is a limitation in the analysis that I wanted to address some day, and it's great that there is as a Bugzilla report for it now.
I've changed the report to an enhancement, and changed the title to reflect the problem. I've also accepted the bug.
The checker doesn't evaluate all iterations of the loop. This may just be "not to be fixed".
assigned to @tkremenek