[cfe-commits] r61260 - in /cfe/trunk: include/clang/AST/Expr.h lib/AST/Expr.cpp lib/AST/ExprConstant.cpp lib/Sema/SemaDecl.cpp
Anders Carlsson
andersca at mac.com
Fri Dec 19 12:58:06 PST 2008
Author: andersca
Date: Fri Dec 19 14:58:05 2008
New Revision: 61260
URL: http://llvm.org/viewvc/llvm-project?rev=61260&view=rev
Log:
Get rid of the old Expr::Evaluate variant.
Modified:
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/lib/AST/Expr.cpp
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=61260&r1=61259&r2=61260&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Fri Dec 19 14:58:05 2008
@@ -208,9 +208,6 @@
/// in Result.
bool Evaluate(EvalResult &Result, ASTContext &Ctx) const;
- // FIXME: We should come up with a better API for the isEvaluated case.
- bool Evaluate(APValue& Result, ASTContext &Ctx, bool *isEvaluated = 0) const;
-
/// isEvaluatable - Call Evaluate to see if this expression can be constant
/// folded, but discard the result.
bool isEvaluatable(ASTContext &Ctx) const;
Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=61260&r1=61259&r2=61260&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Fri Dec 19 14:58:05 2008
@@ -763,9 +763,11 @@
// If this is a call to a builtin function, constant fold it otherwise
// reject it.
if (CE->isBuiltinCall()) {
- APValue ResultAP;
- if (CE->Evaluate(ResultAP, Ctx)) {
- Result = ResultAP.getInt();
+ EvalResult EvalResult;
+ if (CE->Evaluate(EvalResult, Ctx)) {
+ assert(!EvalResult.HasSideEffects &&
+ "Foldable builtin call should not have side effects!");
+ Result = EvalResult.Val.getInt();
break; // It is a constant, expand it.
}
}
Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=61260&r1=61259&r2=61260&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Fri Dec 19 14:58:05 2008
@@ -1194,19 +1194,6 @@
return true;
}
-bool Expr::Evaluate(APValue &Result, ASTContext &Ctx, bool *isEvaluated) const {
- EvalResult EvalResult;
-
- if (!Evaluate(EvalResult, Ctx))
- return false;
-
- Result = EvalResult.Val;
- if (isEvaluated)
- *isEvaluated = !EvalResult.HasSideEffects;
-
- return true;
-}
-
/// isEvaluatable - Call Evaluate to see if this expression can be constant
/// folded, but discard the result.
bool Expr::isEvaluatable(ASTContext &Ctx) const {
@@ -1215,10 +1202,10 @@
}
APSInt Expr::EvaluateAsInt(ASTContext &Ctx) const {
- APValue V;
- bool Result = Evaluate(V, Ctx);
+ EvalResult EvalResult;
+ bool Result = Evaluate(EvalResult, Ctx);
assert(Result && "Could not evaluate expression");
- assert(V.isInt() && "Expression did not evaluate to integer");
+ assert(EvalResult.Val.isInt() && "Expression did not evaluate to integer");
- return V.getInt();
+ return EvalResult.Val.getInt();
}
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=61260&r1=61259&r2=61260&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Dec 19 14:58:05 2008
@@ -1888,8 +1888,9 @@
// should always be able to do in theory). If so, we only require the
// specified arm of the conditional to be a constant. This is a horrible
// hack, but is require by real world code that uses __builtin_constant_p.
- APValue Val;
- if (!Exp->getCond()->Evaluate(Val, Context)) {
+ Expr::EvalResult EvalResult;
+ if (!Exp->getCond()->Evaluate(EvalResult, Context) ||
+ EvalResult.HasSideEffects) {
// If Evaluate couldn't fold it, CheckArithmeticConstantExpression
// won't be able to either. Use it to emit the diagnostic though.
bool Res = CheckArithmeticConstantExpression(Exp->getCond());
@@ -1899,7 +1900,7 @@
// Verify that the side following the condition is also a constant.
const Expr *TrueSide = Exp->getLHS(), *FalseSide = Exp->getRHS();
- if (Val.getInt() == 0)
+ if (EvalResult.Val.getInt() == 0)
std::swap(TrueSide, FalseSide);
if (TrueSide && CheckArithmeticConstantExpression(TrueSide))
@@ -2717,13 +2718,13 @@
const VariableArrayType* VLATy = dyn_cast<VariableArrayType>(T);
if (!VLATy) return QualType();
- APValue Result;
+ Expr::EvalResult EvalResult;
if (!VLATy->getSizeExpr() ||
- !VLATy->getSizeExpr()->Evaluate(Result, Context))
+ !VLATy->getSizeExpr()->Evaluate(EvalResult, Context))
return QualType();
- assert(Result.isInt() && "Size expressions must be integers!");
- llvm::APSInt &Res = Result.getInt();
+ assert(EvalResult.Val.isInt() && "Size expressions must be integers!");
+ llvm::APSInt &Res = EvalResult.Val.getInt();
if (Res > llvm::APSInt(Res.getBitWidth(), Res.isUnsigned()))
return Context.getConstantArrayType(VLATy->getElementType(),
Res, ArrayType::Normal, 0);
More information about the cfe-commits
mailing list