mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-26 17:26:06 +00:00
[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:
parent
0e0ea9ffb8
commit
bcc662484a
@ -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.
|
||||
|
@ -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}}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user