This is an archive of the discontinued LLVM Phabricator instance.

[analyzer] Fix crash on modeling of pointer arithmetic
ClosedPublic

Authored by alexander-shaposhnikov on Sep 22 2017, 11:23 PM.

Details

Summary

This patch attempts to fix analyzer's crash on the newly added test case (see also https://bugs.llvm.org/show_bug.cgi?id=34374).
Pointer subtraction appears to be modeled incorrectly in the following example:

char* p;
long n = p - reinterpret_cast<char*>((unsigned long)1);

In this case the analyzer (built without this patch) tries to create a symbolic value for the difference
treating reinterpret_cast<char*>((unsigned long)1) as an integer, that is not correct.

Test plan: make check-all

Diff Detail

Repository
rL LLVM

Event Timeline

alexander-shaposhnikov edited the summary of this revision. (Show Details)Sep 23 2017, 12:32 AM
NoQ edited edge metadata.Sep 25 2017, 2:01 AM

Looks good!

I guess the accurate thing to do would be to return LocAsInteger of type intptr_t of an ElementRegion with index -1 from SymbolicRegion around p. But i'm totally fine with another UnknownVal placeholder until this becomes an actual problem.

NoQ accepted this revision.Sep 25 2017, 2:02 AM
This revision is now accepted and ready to land.Sep 25 2017, 2:02 AM

Thanks for the fix!

This revision was automatically updated to reflect the committed changes.