summaryrefslogtreecommitdiffstats
path: root/clang/lib/AST/Expr.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-12-12 06:55:44 +0000
committerChris Lattner <sabre@nondot.org>2008-12-12 06:55:44 +0000
commit85b25bc34461552733a03c1c31ad7a922ca56878 (patch)
treec6b494830c31d42541289778e7e2336b5b2eecc3 /clang/lib/AST/Expr.cpp
parent10da53c60c3ca7c6d976048c854d27ece193ed89 (diff)
downloadbcm5719-llvm-85b25bc34461552733a03c1c31ad7a922ca56878.tar.gz
bcm5719-llvm-85b25bc34461552733a03c1c31ad7a922ca56878.zip
implement rdar://6091492 - ?: with __builtin_constant_p as the operand is an i-c-e.
llvm-svn: 60934
Diffstat (limited to 'clang/lib/AST/Expr.cpp')
-rw-r--r--clang/lib/AST/Expr.cpp11
1 files changed, 10 insertions, 1 deletions
diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index 728b13534a3..8d113569259 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -1017,13 +1017,22 @@ bool Expr::isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx,
case ConditionalOperatorClass: {
const ConditionalOperator *Exp = cast<ConditionalOperator>(this);
- if (!Exp->getCond()->isIntegerConstantExpr(Result, Ctx, Loc, isEvaluated))
+ const Expr *Cond = Exp->getCond();
+
+ if (!Cond->isIntegerConstantExpr(Result, Ctx, Loc, isEvaluated))
return false;
const Expr *TrueExp = Exp->getLHS();
const Expr *FalseExp = Exp->getRHS();
if (Result == 0) std::swap(TrueExp, FalseExp);
+ // If the condition (ignoring parens) is a __builtin_constant_p call,
+ // then only the true side is actually considered in an integer constant
+ // expression. This is an important GNU extension.
+ if (const CallExpr *CallCE = dyn_cast<CallExpr>(Cond->IgnoreParenCasts()))
+ if (CallCE->isBuiltinCall() == Builtin::BI__builtin_constant_p)
+ FalseExp = 0;
+
// Evaluate the false one first, discard the result.
if (FalseExp && !FalseExp->isIntegerConstantExpr(Result, Ctx, Loc, false))
return false;
OpenPOWER on IntegriCloud