Skip to content
Snippets Groups Projects
Commit da396034 authored by Anna Zaks's avatar Anna Zaks
Browse files

[analyzer] Do not assert on constructing SymSymExpr with diff types.

The resulting type info is stored in the SymSymExpr, so no reason not to
support construction of expression with different subexpression types.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@156051 91177308-0d34-0410-b5e6-96231b3b80d8
parent baeaa9ad
No related branches found
No related tags found
No related merge requests found
...@@ -61,7 +61,6 @@ NonLoc SValBuilder::makeNonLoc(const llvm::APSInt& lhs, ...@@ -61,7 +61,6 @@ NonLoc SValBuilder::makeNonLoc(const llvm::APSInt& lhs,
NonLoc SValBuilder::makeNonLoc(const SymExpr *lhs, BinaryOperator::Opcode op, NonLoc SValBuilder::makeNonLoc(const SymExpr *lhs, BinaryOperator::Opcode op,
const SymExpr *rhs, QualType type) { const SymExpr *rhs, QualType type) {
assert(lhs && rhs); assert(lhs && rhs);
assert(haveSameType(lhs->getType(Context), rhs->getType(Context)) == true);
assert(!Loc::isLocType(type)); assert(!Loc::isLocType(type));
return nonloc::SymbolVal(SymMgr.getSymSymExpr(lhs, op, rhs, type)); return nonloc::SymbolVal(SymMgr.getSymSymExpr(lhs, op, rhs, type));
} }
......
...@@ -280,6 +280,9 @@ SVal SimpleSValBuilder::evalBinOpNN(ProgramStateRef state, ...@@ -280,6 +280,9 @@ SVal SimpleSValBuilder::evalBinOpNN(ProgramStateRef state,
BinaryOperator::Opcode op, BinaryOperator::Opcode op,
NonLoc lhs, NonLoc rhs, NonLoc lhs, NonLoc rhs,
QualType resultTy) { QualType resultTy) {
NonLoc InputLHS = lhs;
NonLoc InputRHS = rhs;
// Handle trivial case where left-side and right-side are the same. // Handle trivial case where left-side and right-side are the same.
if (lhs == rhs) if (lhs == rhs)
switch (op) { switch (op) {
...@@ -327,7 +330,7 @@ SVal SimpleSValBuilder::evalBinOpNN(ProgramStateRef state, ...@@ -327,7 +330,7 @@ SVal SimpleSValBuilder::evalBinOpNN(ProgramStateRef state,
return makeTruthVal(true, resultTy); return makeTruthVal(true, resultTy);
default: default:
// This case also handles pointer arithmetic. // This case also handles pointer arithmetic.
return makeSymExprValNN(state, op, lhs, rhs, resultTy); return makeSymExprValNN(state, op, InputLHS, InputRHS, resultTy);
} }
} }
} }
...@@ -389,9 +392,9 @@ SVal SimpleSValBuilder::evalBinOpNN(ProgramStateRef state, ...@@ -389,9 +392,9 @@ SVal SimpleSValBuilder::evalBinOpNN(ProgramStateRef state,
if (lhsValue == 0) if (lhsValue == 0)
// At this point lhs and rhs have been swapped. // At this point lhs and rhs have been swapped.
return rhs; return rhs;
return makeSymExprValNN(state, op, rhs, lhs, resultTy); return makeSymExprValNN(state, op, InputLHS, InputRHS, resultTy);
default: default:
return makeSymExprValNN(state, op, rhs, lhs, resultTy); return makeSymExprValNN(state, op, InputLHS, InputRHS, resultTy);
} }
} }
} }
...@@ -406,7 +409,7 @@ SVal SimpleSValBuilder::evalBinOpNN(ProgramStateRef state, ...@@ -406,7 +409,7 @@ SVal SimpleSValBuilder::evalBinOpNN(ProgramStateRef state,
dyn_cast<SymIntExpr>(selhs->getSymbol()); dyn_cast<SymIntExpr>(selhs->getSymbol());
if (!symIntExpr) if (!symIntExpr)
return makeSymExprValNN(state, op, lhs, rhs, resultTy); return makeSymExprValNN(state, op, InputLHS, InputRHS, resultTy);
// Is this a logical not? (!x is represented as x == 0.) // Is this a logical not? (!x is represented as x == 0.)
if (op == BO_EQ && rhs.isZeroConstant()) { if (op == BO_EQ && rhs.isZeroConstant()) {
...@@ -454,7 +457,7 @@ SVal SimpleSValBuilder::evalBinOpNN(ProgramStateRef state, ...@@ -454,7 +457,7 @@ SVal SimpleSValBuilder::evalBinOpNN(ProgramStateRef state,
// For now, only handle expressions whose RHS is a constant. // For now, only handle expressions whose RHS is a constant.
const nonloc::ConcreteInt *rhsInt = dyn_cast<nonloc::ConcreteInt>(&rhs); const nonloc::ConcreteInt *rhsInt = dyn_cast<nonloc::ConcreteInt>(&rhs);
if (!rhsInt) if (!rhsInt)
return makeSymExprValNN(state, op, lhs, rhs, resultTy); return makeSymExprValNN(state, op, InputLHS, InputRHS, resultTy);
// If both the LHS and the current expression are additive, // If both the LHS and the current expression are additive,
// fold their constants. // fold their constants.
...@@ -539,7 +542,7 @@ SVal SimpleSValBuilder::evalBinOpNN(ProgramStateRef state, ...@@ -539,7 +542,7 @@ SVal SimpleSValBuilder::evalBinOpNN(ProgramStateRef state,
resultTy); resultTy);
} }
return makeSymExprValNN(state, op, lhs, rhs, resultTy); return makeSymExprValNN(state, op, InputLHS, InputRHS, resultTy);
} }
} }
} }
......
...@@ -203,3 +203,12 @@ unsigned radar11369570_hanging(const unsigned char *arr, int l) { ...@@ -203,3 +203,12 @@ unsigned radar11369570_hanging(const unsigned char *arr, int l) {
} }
return 5/a; // expected-warning {{Division by a tainted value, possibly zero}} return 5/a; // expected-warning {{Division by a tainted value, possibly zero}}
} }
// Check that we do not assert of the following code.
int SymSymExprWithDiffTypes(void* p) {
int i;
scanf("%d", &i);
int j = (i % (int)(long)p);
return 5/j; // expected-warning {{Division by a tainted value, possibly zero}}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment