]> granicus.if.org Git - clang/commitdiff
[analyzer] Always use 'bool' as the SValBuilder condition type in C++.
authorJordan Rose <jordan_rose@apple.com>
Thu, 19 Dec 2013 22:32:39 +0000 (22:32 +0000)
committerJordan Rose <jordan_rose@apple.com>
Thu, 19 Dec 2013 22:32:39 +0000 (22:32 +0000)
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

lib/StaticAnalyzer/Core/ExprEngine.cpp
lib/StaticAnalyzer/Core/SValBuilder.cpp
test/Analysis/casts.cpp

index 36be970485e84bce75eaf6154a0b2d41fe84027b..e7b1e1fde8dd897b720766e1ddf612d9d224d515 100644 (file)
@@ -118,7 +118,7 @@ ProgramStateRef ExprEngine::getInitialState(const LocationContext *InitLoc) {
       SVal V = state->getSVal(loc::MemRegionVal(R));
       SVal Constraint_untested = evalBinOp(state, BO_GT, V,
                                            svalBuilder.makeZeroVal(T),
-                                           getContext().IntTy);
+                                           svalBuilder.getConditionType());
 
       Optional<DefinedOrUnknownSVal> Constraint =
           Constraint_untested.getAs<DefinedOrUnknownSVal>();
index 38d7e5a427cc0a5265028bf056d1f2e2b88f830c..3ed2bde1e4f8452f045d83b8fab20cd6a867235d 100644 (file)
@@ -362,7 +362,7 @@ SVal SValBuilder::evalBinOp(ProgramStateRef state, BinaryOperator::Opcode op,
 DefinedOrUnknownSVal SValBuilder::evalEQ(ProgramStateRef state,
                                          DefinedOrUnknownSVal lhs,
                                          DefinedOrUnknownSVal rhs) {
-  return evalBinOp(state, BO_EQ, lhs, rhs, Context.IntTy)
+  return evalBinOp(state, BO_EQ, lhs, rhs, getConditionType())
       .castAs<DefinedOrUnknownSVal>();
 }
 
index 339539189ed7b1fe20a1e4c29d5c3dfa531258c9..763f942ede6b4335e75fb4d8299daa4710d08220 100644 (file)
@@ -10,3 +10,10 @@ bool PR14634_implicit(int x) {
   double y = (double)x;
   return y;
 }
+
+void intAsBoolAsSwitchCondition(int c) {
+  switch ((bool)c) {
+  case 0:
+    break;
+  }
+}