[analyzer] Crash fix for alpha.cplusplus.IteratorRange

If the non-iterator side of an iterator operation
`+`, `+=`, `-` or `-=` is `UndefinedVal` an assertions happens.
This small fix prevents this.

Patch by Adam Balogh.

Reviewed By: NoQ

Differential Revision: https://reviews.llvm.org/D85424
This commit is contained in:
Adam Balogh 2021-03-10 12:41:01 +01:00 committed by Balazs Benics
parent 0e0ea9ffb8
commit bcc662484a
2 changed files with 8 additions and 1 deletions

View File

@ -228,7 +228,7 @@ void IteratorRangeChecker::verifyRandomIncrOrDecr(CheckerContext &C,
Value = State->getRawSVal(*ValAsLoc);
}
if (Value.isUnknown())
if (Value.isUnknownOrUndef())
return;
// Incremention or decremention by 0 is never a bug.

View File

@ -939,3 +939,10 @@ void ptr_iter_diff(cont_with_ptr_iterator<S> &c) {
auto i0 = c.begin(), i1 = c.end();
ptrdiff_t len = i1 - i0; // no-crash
}
int uninit_var(int n) {
int uninit; // expected-note{{'uninit' declared without an initial value}}
return n - uninit; // no-crash
// expected-warning@-1 {{The right operand of '-' is a garbage value}}
// expected-note@-2 {{The right operand of '-' is a garbage value}}
}