From b7d549d2c25575e81b60ee507b81dd079912f5e6 Mon Sep 17 00:00:00 2001 From: Jordan Rose Date: Thu, 19 Dec 2013 22:32:39 +0000 Subject: [PATCH] [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'. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@197733 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/StaticAnalyzer/Core/ExprEngine.cpp | 2 +- lib/StaticAnalyzer/Core/SValBuilder.cpp | 2 +- test/Analysis/casts.cpp | 7 +++++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/StaticAnalyzer/Core/ExprEngine.cpp b/lib/StaticAnalyzer/Core/ExprEngine.cpp index 36be970485..e7b1e1fde8 100644 --- a/lib/StaticAnalyzer/Core/ExprEngine.cpp +++ b/lib/StaticAnalyzer/Core/ExprEngine.cpp @@ -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 Constraint = Constraint_untested.getAs(); diff --git a/lib/StaticAnalyzer/Core/SValBuilder.cpp b/lib/StaticAnalyzer/Core/SValBuilder.cpp index 38d7e5a427..3ed2bde1e4 100644 --- a/lib/StaticAnalyzer/Core/SValBuilder.cpp +++ b/lib/StaticAnalyzer/Core/SValBuilder.cpp @@ -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(); } diff --git a/test/Analysis/casts.cpp b/test/Analysis/casts.cpp index 339539189e..763f942ede 100644 --- a/test/Analysis/casts.cpp +++ b/test/Analysis/casts.cpp @@ -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; + } +} -- 2.50.1