Dear All,
I would like to propose a patch to fix an assertion.
Given the following test case:
----------------------------->
void f1(long foo) { unsigned index = -1; if (index < foo) index = foo; if (index + 1 == 0) // -> "system over constrained" assertion clang_analyzer_warnIfReached(); // -> never reached but should be else clang_analyzer_warnIfReached(); }
<-----------------------------
Using a debug build:
----------------------------->
$ clang -cc1 -triple x86_64-pc-linux-gnu -analyze -analyzer-checker=core,debug.ExprInspection test.cpp clang: ../tools/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h:86: clang::ento::ConstraintManager::ProgramStatePair clang::ento::ConstraintManager::assumeDual(clang::ento::ProgramStateRef,
clang::ento::DefinedSVal): Assertion `assume(State, Cond, false) && "System is over constrained."' failed.
<-----------------------------
When evaluating the condition "index + 1 == 0", the analyzer checks if the range of 'index' can intersect the value UINT_MAX.
Unfortunately ranges do not get updated on assignments, the range of index is the 64 bit signed range of 'foo' which is [UINT_MAX + 1; LONG_MAX] which does not intersect [UINT_MAX; UINT_MAX] or [0; UINT_MAX - 1], hence causing the assertion.
Can you let me know if this seems a reasonable change and eventually commit it for me?
Regards,
Pierre Gousseau
SN Systems - Sony Computer Entertainment
SValBuilder::evalCast and SimpleSValBuilder::evalCastFromNonLoc perform a lot of special casing. I am not sure we are not loosing anything if we bypass them. For example, there is special handling of Booleans. We might want to add this smarter handling of the integral conversions inside SimpleSValBuilder::evalCastFromNonLoc, where you see the comment starting with "If the types are the same or both are integers, ignore the cast."