Skip to content

(rdar://77686137) Fix crash in the static analyzer constraint solver component #2961

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1487,15 +1487,18 @@ class RangeConstraintManager : public RangedConstraintManager {
// This is an infeasible assumption.
return nullptr;

ProgramStateRef NewState = setConstraint(State, Sym, NewConstraint);
if (auto Equality = EqualityInfo::extract(Sym, Int, Adjustment)) {
// If the original assumption is not Sym + Adjustment !=/</> Int,
// we should invert IsEquality flag.
Equality->IsEquality = Equality->IsEquality != EQ;
return track(NewState, *Equality);
if (ProgramStateRef NewState = setConstraint(State, Sym, NewConstraint)) {
if (auto Equality = EqualityInfo::extract(Sym, Int, Adjustment)) {
// If the original assumption is not Sym + Adjustment !=/</> Int,
// we should invert IsEquality flag.
Equality->IsEquality = Equality->IsEquality != EQ;
return track(NewState, *Equality);
}

return NewState;
}

return NewState;
return nullptr;
}

ProgramStateRef track(ProgramStateRef State, EqualityInfo ToTrack) {
Expand Down
12 changes: 12 additions & 0 deletions clang/test/Analysis/PR50268.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// RUN: %clang_analyze_cc1 -w -analyzer-checker=core -verify %s \
// RUN: -analyzer-config eagerly-assume=true

// expected-no-diagnostics


int test(unsigned long a, unsigned long c, int b) {
c -= a;
if (0 >= b) {}
c == b;
return c ? 0 : 2; // no-crash
}