Skip to content
Snippets Groups Projects
Commit b7d549d2 authored by Jordan Rose's avatar Jordan Rose
Browse files

[analyzer] Always use 'bool' as the SValBuilder condition type in C++.

We have assertions for this, but a few edge cases had snuck through where
we were still unconditionally using 'int'.

<rdar://problem/15703011>

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@197733 91177308-0d34-0410-b5e6-96231b3b80d8
parent 45e0c0d8
No related branches found
No related tags found
No related merge requests found
...@@ -118,7 +118,7 @@ ProgramStateRef ExprEngine::getInitialState(const LocationContext *InitLoc) { ...@@ -118,7 +118,7 @@ ProgramStateRef ExprEngine::getInitialState(const LocationContext *InitLoc) {
SVal V = state->getSVal(loc::MemRegionVal(R)); SVal V = state->getSVal(loc::MemRegionVal(R));
SVal Constraint_untested = evalBinOp(state, BO_GT, V, SVal Constraint_untested = evalBinOp(state, BO_GT, V,
svalBuilder.makeZeroVal(T), svalBuilder.makeZeroVal(T),
getContext().IntTy); svalBuilder.getConditionType());
Optional<DefinedOrUnknownSVal> Constraint = Optional<DefinedOrUnknownSVal> Constraint =
Constraint_untested.getAs<DefinedOrUnknownSVal>(); Constraint_untested.getAs<DefinedOrUnknownSVal>();
......
...@@ -362,7 +362,7 @@ SVal SValBuilder::evalBinOp(ProgramStateRef state, BinaryOperator::Opcode op, ...@@ -362,7 +362,7 @@ SVal SValBuilder::evalBinOp(ProgramStateRef state, BinaryOperator::Opcode op,
DefinedOrUnknownSVal SValBuilder::evalEQ(ProgramStateRef state, DefinedOrUnknownSVal SValBuilder::evalEQ(ProgramStateRef state,
DefinedOrUnknownSVal lhs, DefinedOrUnknownSVal lhs,
DefinedOrUnknownSVal rhs) { DefinedOrUnknownSVal rhs) {
return evalBinOp(state, BO_EQ, lhs, rhs, Context.IntTy) return evalBinOp(state, BO_EQ, lhs, rhs, getConditionType())
.castAs<DefinedOrUnknownSVal>(); .castAs<DefinedOrUnknownSVal>();
} }
......
...@@ -10,3 +10,10 @@ bool PR14634_implicit(int x) { ...@@ -10,3 +10,10 @@ bool PR14634_implicit(int x) {
double y = (double)x; double y = (double)x;
return y; return y;
} }
void intAsBoolAsSwitchCondition(int c) {
switch ((bool)c) {
case 0:
break;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment