Skip to content

Commit f9db6a4

Browse files
author
Balazs Benics
committed
Revert "[analyzer][solver] Introduce reasoning for not equal to operator"
This reverts commit cac8808. #5 0x00007f28ec629859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x25859) #6 0x00007f28ec629729 (/lib/x86_64-linux-gnu/libc.so.6+0x25729) #7 0x00007f28ec63af36 (/lib/x86_64-linux-gnu/libc.so.6+0x36f36) #8 0x00007f28ecc2cc46 llvm::APInt::compareSigned(llvm::APInt const&) const (libLLVMSupport.so.14git+0xeac46) #9 0x00007f28e7bbf957 (anonymous namespace)::SymbolicRangeInferrer::VisitBinaryOperator(clang::ento::RangeSet, clang::BinaryOperatorKind, clang::ento::RangeSet, clang::QualType) (libclangStaticAnalyzerCore.so.14git+0x1df957) #10 0x00007f28e7bbf2db (anonymous namespace)::SymbolicRangeInferrer::infer(clang::ento::SymExpr const*) (libclangStaticAnalyzerCore.so.14git+0x1df2db) #11 0x00007f28e7bb2b5e (anonymous namespace)::RangeConstraintManager::assumeSymNE(llvm::IntrusiveRefCntPtr<clang::ento::ProgramState const>, clang::ento::SymExpr const*, llvm::APSInt const&, llvm::APSInt const&) (libclangStaticAnalyzerCore.so.14git+0x1d2b5e) #12 0x00007f28e7bc67af clang::ento::RangedConstraintManager::assumeSymUnsupported(llvm::IntrusiveRefCntPtr<clang::ento::ProgramState const>, clang::ento::SymExpr const*, bool) (libclangStaticAnalyzerCore.so.14git+0x1e67af) #13 0x00007f28e7be3578 clang::ento::SimpleConstraintManager::assumeAux(llvm::IntrusiveRefCntPtr<clang::ento::ProgramState const>, clang::ento::NonLoc, bool) (libclangStaticAnalyzerCore.so.14git+0x203578) #14 0x00007f28e7be33d8 clang::ento::SimpleConstraintManager::assume(llvm::IntrusiveRefCntPtr<clang::ento::ProgramState const>, clang::ento::NonLoc, bool) (libclangStaticAnalyzerCore.so.14git+0x2033d8) #15 0x00007f28e7be32fb clang::ento::SimpleConstraintManager::assume(llvm::IntrusiveRefCntPtr<clang::ento::ProgramState const>, clang::ento::DefinedSVal, bool) (libclangStaticAnalyzerCore.so.14git+0x2032fb) #16 0x00007f28e7b15dbc clang::ento::ConstraintManager::assumeDual(llvm::IntrusiveRefCntPtr<clang::ento::ProgramState const>, clang::ento::DefinedSVal) (libclangStaticAnalyzerCore.so.14git+0x135dbc) #17 0x00007f28e7b4780f clang::ento::ExprEngine::evalEagerlyAssumeBinOpBifurcation(clang::ento::ExplodedNodeSet&, clang::ento::ExplodedNodeSet&, clang::Expr const*) (libclangStaticAnalyzerCore.so.14git+0x16780f) This is known to be triggered on curl, tinyxml2, tmux, twin and on xerces. But @bjope also reported similar crashes. So, I'm reverting it to make our internal bots happy again. Differential Revision: https://reviews.llvm.org/D106102
1 parent 710596a commit f9db6a4

File tree

2 files changed

+13
-88
lines changed

2 files changed

+13
-88
lines changed

clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp

+13-42
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
#include "llvm/ADT/FoldingSet.h"
2121
#include "llvm/ADT/ImmutableSet.h"
2222
#include "llvm/ADT/STLExtras.h"
23-
#include "llvm/ADT/SmallSet.h"
2423
#include "llvm/ADT/StringExtras.h"
24+
#include "llvm/ADT/SmallSet.h"
2525
#include "llvm/Support/Compiler.h"
2626
#include "llvm/Support/raw_ostream.h"
2727
#include <algorithm>
@@ -955,7 +955,18 @@ class SymbolicRangeInferrer
955955
}
956956

957957
RangeSet VisitBinaryOperator(RangeSet LHS, BinaryOperator::Opcode Op,
958-
RangeSet RHS, QualType T);
958+
RangeSet RHS, QualType T) {
959+
switch (Op) {
960+
case BO_Or:
961+
return VisitBinaryOperator<BO_Or>(LHS, RHS, T);
962+
case BO_And:
963+
return VisitBinaryOperator<BO_And>(LHS, RHS, T);
964+
case BO_Rem:
965+
return VisitBinaryOperator<BO_Rem>(LHS, RHS, T);
966+
default:
967+
return infer(T);
968+
}
969+
}
959970

960971
//===----------------------------------------------------------------------===//
961972
// Ranges and operators
@@ -1220,29 +1231,6 @@ class SymbolicRangeInferrer
12201231
// Range-based reasoning about symbolic operations
12211232
//===----------------------------------------------------------------------===//
12221233

1223-
template <>
1224-
RangeSet SymbolicRangeInferrer::VisitBinaryOperator<BO_NE>(RangeSet LHS,
1225-
RangeSet RHS,
1226-
QualType T) {
1227-
// When both the RangeSets are non-overlapping then all possible pairs of
1228-
// (x, y) in LHS, RHS respectively, will satisfy expression (x != y).
1229-
if ((LHS.getMaxValue() < RHS.getMinValue()) ||
1230-
(LHS.getMinValue() > RHS.getMaxValue())) {
1231-
return getTrueRange(T);
1232-
}
1233-
1234-
// If both RangeSets contain only one Point which is equal then the
1235-
// expression will always return true.
1236-
if ((LHS.getMinValue() == RHS.getMaxValue()) &&
1237-
(LHS.getMaxValue() == RHS.getMaxValue()) &&
1238-
(LHS.getMinValue() == RHS.getMinValue())) {
1239-
return getFalseRange(T);
1240-
}
1241-
1242-
// In all other cases, the resulting range cannot be deduced.
1243-
return infer(T);
1244-
}
1245-
12461234
template <>
12471235
RangeSet SymbolicRangeInferrer::VisitBinaryOperator<BO_Or>(Range LHS, Range RHS,
12481236
QualType T) {
@@ -1403,23 +1391,6 @@ RangeSet SymbolicRangeInferrer::VisitBinaryOperator<BO_Rem>(Range LHS,
14031391
return {RangeFactory, ValueFactory.getValue(Min), ValueFactory.getValue(Max)};
14041392
}
14051393

1406-
RangeSet SymbolicRangeInferrer::VisitBinaryOperator(RangeSet LHS,
1407-
BinaryOperator::Opcode Op,
1408-
RangeSet RHS, QualType T) {
1409-
switch (Op) {
1410-
case BO_NE:
1411-
return VisitBinaryOperator<BO_NE>(LHS, RHS, T);
1412-
case BO_Or:
1413-
return VisitBinaryOperator<BO_Or>(LHS, RHS, T);
1414-
case BO_And:
1415-
return VisitBinaryOperator<BO_And>(LHS, RHS, T);
1416-
case BO_Rem:
1417-
return VisitBinaryOperator<BO_Rem>(LHS, RHS, T);
1418-
default:
1419-
return infer(T);
1420-
}
1421-
}
1422-
14231394
//===----------------------------------------------------------------------===//
14241395
// Constraint manager implementation details
14251396
//===----------------------------------------------------------------------===//

clang/test/Analysis/constant-folding.c

-46
Original file line numberDiff line numberDiff line change
@@ -281,49 +281,3 @@ void testRemainderRules(unsigned int a, unsigned int b, int c, int d) {
281281
clang_analyzer_eval((b % a) < x + 10); // expected-warning{{TRUE}}
282282
}
283283
}
284-
285-
void testDisequalityRules(unsigned int u1, unsigned int u2, int s1, int s2) {
286-
// Checks when ranges are not overlapping
287-
if (u1 <= 10 && u2 >= 20) {
288-
// u1: [0,10], u2: [20,UINT_MAX]
289-
clang_analyzer_eval((u1 != u2) != 0); // expected-warning{{TRUE}}
290-
}
291-
292-
if (s1 <= INT_MIN + 10 && s2 >= INT_MAX - 10) {
293-
// s1: [INT_MIN,INT_MIN + 10], s2: [INT_MAX - 10,INT_MAX]
294-
clang_analyzer_eval((s1 != s2) == 0); // expected-warning{{FALSE}}
295-
}
296-
297-
// Checks when ranges are completely overlapping and have more than one point
298-
if (u1 >= 20 && u1 <= 50 && u2 >= 20 && u2 <= 50) {
299-
// u1: [20,50], u2: [20,50]
300-
clang_analyzer_eval((u1 != u2) != 0); // expected-warning{{UNKNOWN}}
301-
}
302-
303-
if (s1 >= -20 && s1 <= 20 && s2 >= -20 && s2 <= 20) {
304-
// s1: [-20,20], s2: [-20,20]
305-
clang_analyzer_eval((s1 != s2) != 0); // expected-warning{{UNKNOWN}}
306-
}
307-
308-
// Checks when ranges are partially overlapping
309-
if (u1 >= 100 && u1 <= 200 && u2 >= 150 && u2 <= 300) {
310-
// u1: [100,200], u2: [150,300]
311-
clang_analyzer_eval((u1 != u2) != 0); // expected-warning{{UNKNOWN}}
312-
}
313-
314-
if (s1 >= -80 && s1 <= -50 && s2 >= -100 && s2 <= -75) {
315-
// s1: [-80,-50], s2: [-100,-75]
316-
clang_analyzer_eval((s1 != s2) == 0); // expected-warning{{UNKNOWN}}
317-
}
318-
319-
// Checks for ranges which are subset of one-another
320-
if (u1 >= 500 && u1 <= 1000 && u2 >= 750 && u2 <= 1000) {
321-
// u1: [500,1000], u2: [750,1000]
322-
clang_analyzer_eval((u1 != u2) == 0); // expected-warning{{UNKNOWN}}
323-
}
324-
325-
if (s1 >= -1000 && s1 <= -500 && s2 <= -500 && s2 >= -750) {
326-
// s1: [-1000,-500], s2: [-500,-750]
327-
clang_analyzer_eval((s1 != s2) == 0); // expected-warning{{UNKNOWN}}
328-
}
329-
}

0 commit comments

Comments
 (0)