[cfe-commits] r66018 - in /cfe/trunk: include/clang/AST/Expr.h lib/AST/Expr.cpp lib/AST/ExprConstant.cpp lib/CodeGen/CGExpr.cpp lib/CodeGen/CGExprComplex.cpp lib/CodeGen/CGExprScalar.cpp
Eli Friedman
eli.friedman at gmail.com
Tue Mar 3 21:52:32 PST 2009
Author: efriedma
Date: Tue Mar 3 23:52:32 2009
New Revision: 66018
URL: http://llvm.org/viewvc/llvm-project?rev=66018&view=rev
Log:
Minor cleanup for choose expressions: add a helper that returns the
chosen sub-expression, rather than just evaluating the condition.
Modified:
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/lib/AST/Expr.cpp
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/CodeGen/CGExprComplex.cpp
cfe/trunk/lib/CodeGen/CGExprScalar.cpp
Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=66018&r1=66017&r2=66018&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Tue Mar 3 23:52:32 2009
@@ -1493,9 +1493,12 @@
/// ChooseExpr - GNU builtin-in function __builtin_choose_expr.
/// This AST node is similar to the conditional operator (?:) in C, with
/// the following exceptions:
-/// - the test expression must be a constant expression.
-/// - the expression returned has it's type unaltered by promotion rules.
-/// - does not evaluate the expression that was not chosen.
+/// - the test expression must be a integer constant expression.
+/// - the expression returned acts like the chosen subexpression in every
+/// visible way: the type is the same as that of the chosen subexpression,
+/// and all predicates (whether it's an l-value, whether it's an integer
+/// constant expression, etc.) return the same result as for the chosen
+/// sub-expression.
class ChooseExpr : public Expr {
enum { COND, LHS, RHS, END_EXPR };
Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides.
@@ -1509,11 +1512,17 @@
SubExprs[LHS] = lhs;
SubExprs[RHS] = rhs;
}
-
- /// isConditionTrue - Return true if the condition is true. This is always
- /// statically knowable for a well-formed choosexpr.
+
+ /// isConditionTrue - Return whether the condition is true (i.e. not
+ /// equal to zero).
bool isConditionTrue(ASTContext &C) const;
-
+
+ /// getChosenSubExpr - Return the subexpression chosen according to the
+ /// condition.
+ Expr *getChosenSubExpr(ASTContext &C) const {
+ return isConditionTrue(C) ? getLHS() : getRHS();
+ }
+
Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=66018&r1=66017&r2=66018&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Tue Mar 3 23:52:32 2009
@@ -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);
}
}
}
Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=66018&r1=66017&r2=66018&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Tue Mar 3 23:52:32 2009
@@ -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) {
Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=66018&r1=66017&r2=66018&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Tue Mar 3 23:52:32 2009
@@ -178,11 +178,7 @@
case Expr::CompoundLiteralExprClass:
return EmitCompoundLiteralLValue(cast<CompoundLiteralExpr>(E));
case Expr::ChooseExprClass:
- // __builtin_choose_expr is the lvalue of the selected operand.
- if (cast<ChooseExpr>(E)->isConditionTrue(getContext()))
- return EmitLValue(cast<ChooseExpr>(E)->getLHS());
- else
- return EmitLValue(cast<ChooseExpr>(E)->getRHS());
+ return EmitLValue(cast<ChooseExpr>(E)->getChosenSubExpr(getContext()));
}
}
Modified: cfe/trunk/lib/CodeGen/CGExprComplex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprComplex.cpp?rev=66018&r1=66017&r2=66018&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprComplex.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprComplex.cpp Tue Mar 3 23:52:32 2009
@@ -509,8 +509,7 @@
}
ComplexPairTy ComplexExprEmitter::VisitChooseExpr(ChooseExpr *E) {
- // Emit the LHS or RHS as appropriate.
- return Visit(E->isConditionTrue(CGF.getContext()) ? E->getLHS() :E->getRHS());
+ return Visit(E->getChosenSubExpr(CGF.getContext()));
}
ComplexPairTy ComplexExprEmitter::VisitInitListExpr(InitListExpr *E) {
Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=66018&r1=66017&r2=66018&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Tue Mar 3 23:52:32 2009
@@ -1307,9 +1307,7 @@
}
Value *ScalarExprEmitter::VisitChooseExpr(ChooseExpr *E) {
- // Emit the LHS or RHS as appropriate.
- return
- Visit(E->isConditionTrue(CGF.getContext()) ? E->getLHS() : E->getRHS());
+ return Visit(E->getChosenSubExpr(CGF.getContext()));
}
Value *ScalarExprEmitter::VisitVAArgExpr(VAArgExpr *VE) {
More information about the cfe-commits
mailing list