diff options
| author | Chris Lattner <sabre@nondot.org> | 2008-12-12 18:00:51 +0000 | 
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2008-12-12 18:00:51 +0000 | 
| commit | 04397358ec738932d6b87f7d8d7843c8650c0c78 (patch) | |
| tree | c4dccb07e73bca216d2ce322005b86f5e2b667a6 /clang/lib/AST/Expr.cpp | |
| parent | 729bf137a847f50b0ab123e2c23e50e1025a7ca0 (diff) | |
| download | bcm5719-llvm-04397358ec738932d6b87f7d8d7843c8650c0c78.tar.gz bcm5719-llvm-04397358ec738932d6b87f7d8d7843c8650c0c78.zip | |
Implement the final (hopefully) wrinkle to i-c-e + builtin_constant_p 
processing: it allows arbitrary foldable constants as the operand of ?: when
builtin_constant_p is the condition.
llvm-svn: 60954
Diffstat (limited to 'clang/lib/AST/Expr.cpp')
| -rw-r--r-- | clang/lib/AST/Expr.cpp | 18 | 
1 files changed, 11 insertions, 7 deletions
| diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp index bdc5096584a..c01c973cf59 100644 --- a/clang/lib/AST/Expr.cpp +++ b/clang/lib/AST/Expr.cpp @@ -1028,14 +1028,18 @@ bool Expr::isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx,      // 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. -    // -    // FIXME: ?: with a conditional expr should arguably be an i-c-e if the true -    // side can be folded in any way to a constant.  See GCC PR38377 for -    // discussion. +    // expression, and it is fully evaluated.  This is an important GNU +    // extension.  See GCC PR38377 for discussion.      if (const CallExpr *CallCE = dyn_cast<CallExpr>(Cond->IgnoreParenCasts())) -      if (CallCE->isBuiltinCall() == Builtin::BI__builtin_constant_p) -        FalseExp = 0; +      if (CallCE->isBuiltinCall() == Builtin::BI__builtin_constant_p) { +        EvalResult EVResult; +        if (!Evaluate(EVResult, Ctx) || EVResult.HasSideEffects) +          return false; +        assert(EVResult.Val.isInt() && "FP conditional expr not expected"); +        Result = EVResult.Val.getInt(); +        if (Loc) *Loc = EVResult.DiagLoc; +        return true; +      }      // Evaluate the false one first, discard the result.      if (FalseExp && !FalseExp->isIntegerConstantExpr(Result, Ctx, Loc, false)) | 

