make IntExprEvaluator fold the ?: operator
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59421 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp
index 4a67956..bedc78c 100644
--- a/lib/AST/ExprConstant.cpp
+++ b/lib/AST/ExprConstant.cpp
@@ -397,6 +397,7 @@
bool VisitCallExpr(const CallExpr *E);
bool VisitBinaryOperator(const BinaryOperator *E);
bool VisitUnaryOperator(const UnaryOperator *E);
+ bool VisitConditionalOperator(const ConditionalOperator *E);
bool VisitCastExpr(CastExpr* E) {
return HandleCast(E->getLocStart(), E->getSubExpr(), E->getType());
@@ -725,6 +726,14 @@
return true;
}
+bool IntExprEvaluator::VisitConditionalOperator(const ConditionalOperator *E) {
+ llvm::APSInt Cond(32);
+ if (!EvaluateInteger(E->getCond(), Cond, Info))
+ return false;
+
+ return Visit(Cond != 0 ? E->getTrueExpr() : E->getFalseExpr());
+}
+
/// VisitSizeAlignOfExpr - Evaluate a sizeof or alignof with a result as the
/// expression's type.
bool IntExprEvaluator::VisitSizeOfAlignOfExpr(const SizeOfAlignOfExpr *E) {