/// we want to. If this function returns true, it returns the folded constant
/// in Result.
bool tryEvaluate(APValue& Result, ASTContext &Ctx) const;
+
+ /// isEvaluatable - Call tryEvaluate to see if this expression can be constant
+ /// folded, but discard the result.
+ bool isEvaluatable(ASTContext &Ctx) const;
/// hasGlobalStorage - Return true if this expression has static storage
/// duration. This means that the address of this expression is a link-time
/// not, return 0.
unsigned isBuiltinCall() const;
-
- /// isBuiltinConstantExpr - Return true if this built-in call is constant.
- bool isBuiltinConstantExpr(ASTContext &Ctx) const;
-
SourceLocation getRParenLoc() const { return RParenLoc; }
virtual SourceRange getSourceRange() const {
}
-bool CallExpr::isBuiltinConstantExpr(ASTContext &Ctx) const {
- unsigned BID = isBuiltinCall();
- if (!BID) return false;
- return Ctx.BuiltinInfo.isConstantExpr(BID);
-}
-
/// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
/// corresponds to, e.g. "<<=".
const char *BinaryOperator::getOpcodeStr(Opcode Op) {
return true;
case CallExprClass: {
const CallExpr *CE = cast<CallExpr>(this);
- if (CE->isBuiltinConstantExpr(Ctx))
+
+ // Allow any constant foldable calls to builtins.
+ if (CE->isBuiltinCall() && CE->isEvaluatable(Ctx))
return true;
+
if (Loc) *Loc = getLocStart();
return false;
}
return false;
}
+
+/// isEvaluatable - Call tryEvaluate to see if this expression can be constant
+/// folded, but discard the result.
+bool Expr::isEvaluatable(ASTContext &Ctx) const {
+ APValue V;
+ return tryEvaluate(V, Ctx);
+}
case Expr::StringLiteralClass:
case Expr::ObjCStringLiteralClass:
return false;
- case Expr::CallExprClass: {
- const CallExpr *CE = cast<CallExpr>(Init);
- if (CE->isBuiltinConstantExpr(Context))
- return false;
- Diag(Init->getExprLoc(),
- diag::err_init_element_not_constant, Init->getSourceRange());
- return true;
- }
case Expr::UnaryOperatorClass: {
const UnaryOperator *Exp = cast<UnaryOperator>(Init);
return false;
case Expr::CallExprClass: {
const CallExpr *CE = cast<CallExpr>(Init);
- if (CE->isBuiltinConstantExpr(Context))
+
+ // Allow any constant foldable calls to builtins.
+ if (CE->isBuiltinCall() && CE->isEvaluatable(Context))
return false;
+
Diag(Init->getExprLoc(),
diag::err_init_element_not_constant, Init->getSourceRange());
return true;
// Okay, the evaluated side evaluates to a constant, so we accept this.
// Check to see if the other side is obviously not a constant. If so,
// emit a warning that this is a GNU extension.
- if (FalseSide && !FalseSide->tryEvaluate(Val, Context))
+ if (FalseSide && !FalseSide->isEvaluatable(Context))
Diag(Init->getExprLoc(),
diag::ext_typecheck_expression_not_constant_but_accepted,
FalseSide->getSourceRange());