vsavchenko created this revision. vsavchenko added reviewers: NoQ, martong, steakhal. Herald added subscribers: ASDenysPetrov, dkrupp, donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, rnkovacs, szepet, baloghadamsoftware, xazax.hun. vsavchenko requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
rdar://77686137 Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D102240 Files: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp clang/test/Analysis/PR50268.c Index: clang/test/Analysis/PR50268.c =================================================================== --- /dev/null +++ clang/test/Analysis/PR50268.c @@ -0,0 +1,12 @@ +// RUN: %clang_analyze_cc1 -w -analyzer-checker=core -verify %s + +// expected-no-diagnostics + +unsigned long a, c; +int b; +void d() { + c -= a; + 0 >= b; + c != b; + c ? 0 : 2; // expected no crash +} Index: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp =================================================================== --- clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp +++ clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp @@ -1487,15 +1487,18 @@ // 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) {
Index: clang/test/Analysis/PR50268.c =================================================================== --- /dev/null +++ clang/test/Analysis/PR50268.c @@ -0,0 +1,12 @@ +// RUN: %clang_analyze_cc1 -w -analyzer-checker=core -verify %s + +// expected-no-diagnostics + +unsigned long a, c; +int b; +void d() { + c -= a; + 0 >= b; + c != b; + c ? 0 : 2; // expected no crash +} Index: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp =================================================================== --- clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp +++ clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp @@ -1487,15 +1487,18 @@ // 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) {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits