Minor cleanup for choose expressions: add a helper that returns the
chosen sub-expression, rather than just evaluating the condition.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66018 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp
index d0d14f2..38bcc9b 100644
--- a/lib/AST/Expr.cpp
+++ b/lib/AST/Expr.cpp
@@ -603,11 +603,7 @@
return LV_Valid;
case ChooseExprClass:
// __builtin_choose_expr is an lvalue if the selected operand is.
- if (cast<ChooseExpr>(this)->isConditionTrue(Ctx))
- return cast<ChooseExpr>(this)->getLHS()->isLvalue(Ctx);
- else
- return cast<ChooseExpr>(this)->getRHS()->isLvalue(Ctx);
-
+ return cast<ChooseExpr>(this)->getChosenSubExpr(Ctx)->isLvalue(Ctx);
case ExtVectorElementExprClass:
if (cast<ExtVectorElementExpr>(this)->containsDuplicateElements())
return LV_DuplicateVectorComponents;
@@ -1110,9 +1106,7 @@
case Expr::CXXDefaultArgExprClass:
return CheckICE(cast<CXXDefaultArgExpr>(E)->getExpr(), Ctx);
case Expr::ChooseExprClass: {
- const ChooseExpr *CE = cast<ChooseExpr>(E);
- Expr *SubExpr = CE->isConditionTrue(Ctx) ? CE->getLHS() : CE->getRHS();
- return CheckICE(SubExpr, Ctx);
+ return CheckICE(cast<ChooseExpr>(E)->getChosenSubExpr(Ctx), Ctx);
}
}
}
diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp
index 86a7e82..6fb2abe 100644
--- a/lib/AST/ExprConstant.cpp
+++ b/lib/AST/ExprConstant.cpp
@@ -389,10 +389,8 @@
}
APValue PointerExprEvaluator::VisitChooseExpr(ChooseExpr *E) {
- Expr* EvalExpr = E->isConditionTrue(Info.Ctx) ? E->getLHS() : E->getRHS();
-
APValue Result;
- if (EvaluatePointer(EvalExpr, Result, Info))
+ if (EvaluatePointer(E->getChosenSubExpr(Info.Ctx), Result, Info))
return Result;
return APValue();
}
@@ -522,10 +520,8 @@
}
APValue VectorExprEvaluator::VisitChooseExpr(const ChooseExpr *E) {
- Expr* EvalExpr = E->isConditionTrue(Info.Ctx) ? E->getLHS() : E->getRHS();
-
APValue Result;
- if (EvaluateVector(EvalExpr, Result, Info))
+ if (EvaluateVector(E->getChosenSubExpr(Info.Ctx), Result, Info))
return Result;
return APValue();
}
@@ -1185,9 +1181,7 @@
}
bool IntExprEvaluator::VisitChooseExpr(const ChooseExpr *E) {
- Expr* EvalExpr = E->isConditionTrue(Info.Ctx) ? E->getLHS() : E->getRHS();
-
- return Visit(EvalExpr);
+ return Visit(E->getChosenSubExpr(Info.Ctx));
}
bool IntExprEvaluator::VisitUnaryReal(const UnaryOperator *E) {