This is an archive of the discontinued LLVM Phabricator instance.

Fix ProgramState::isNull for non-region symbols
Needs ReviewPublic

Authored by chrisbazley on Jan 27 2023, 8:54 AM.

Details

Reviewers
NoQ
Summary

This method was good at telling that a pointer
definitely is null, but bad at telling that it
definitely isn't null. For example, it returned
'not sure' in the following trivial case:

int main(void)
{

int p;
int _Optional *q = &p;
if (q) {
  *q = 0; // spurious warning
}
return 0;

}

When analyzing the above program, the statement
if (q) does not create a constraint such as range
[1, 18446744073709551615] for use in future
inferences about the value of q. The reason is
that SimpleConstraintManager::assumeInternal
replaces the condition specified by its caller with
1 if invoked on a symbol (such as q) that lacks an
associated memory region. Constraints are not
recorded for integer constants.

Added fallback in ProgramState::isNull to do the same
conversion and check for a zero result if invoked
on an expression which is not a constant and does
not wrap a symbol (or wraps a symbol that lacks a
memory region).

Diff Detail