Skip to content

Commit d946ed9

Browse files
Merge pull request #2961 from SavchenkoValeriy/vsavchenko/rdar77686137_analyzer_solver_crash
(rdar://77686137) Fix crash in the static analyzer constraint solver component
2 parents 4c31828 + fa54557 commit d946ed9

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,15 +1487,18 @@ class RangeConstraintManager : public RangedConstraintManager {
14871487
// This is an infeasible assumption.
14881488
return nullptr;
14891489

1490-
ProgramStateRef NewState = setConstraint(State, Sym, NewConstraint);
1491-
if (auto Equality = EqualityInfo::extract(Sym, Int, Adjustment)) {
1492-
// If the original assumption is not Sym + Adjustment !=/</> Int,
1493-
// we should invert IsEquality flag.
1494-
Equality->IsEquality = Equality->IsEquality != EQ;
1495-
return track(NewState, *Equality);
1490+
if (ProgramStateRef NewState = setConstraint(State, Sym, NewConstraint)) {
1491+
if (auto Equality = EqualityInfo::extract(Sym, Int, Adjustment)) {
1492+
// If the original assumption is not Sym + Adjustment !=/</> Int,
1493+
// we should invert IsEquality flag.
1494+
Equality->IsEquality = Equality->IsEquality != EQ;
1495+
return track(NewState, *Equality);
1496+
}
1497+
1498+
return NewState;
14961499
}
14971500

1498-
return NewState;
1501+
return nullptr;
14991502
}
15001503

15011504
ProgramStateRef track(ProgramStateRef State, EqualityInfo ToTrack) {

clang/test/Analysis/PR50268.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %clang_analyze_cc1 -w -analyzer-checker=core -verify %s \
2+
// RUN: -analyzer-config eagerly-assume=true
3+
4+
// expected-no-diagnostics
5+
6+
7+
int test(unsigned long a, unsigned long c, int b) {
8+
c -= a;
9+
if (0 >= b) {}
10+
c == b;
11+
return c ? 0 : 2; // no-crash
12+
}

0 commit comments

Comments
 (0)