]> granicus.if.org Git - clang/commitdiff
Get rid of the old Expr::Evaluate variant.
authorAnders Carlsson <andersca@mac.com>
Fri, 19 Dec 2008 20:58:05 +0000 (20:58 +0000)
committerAnders Carlsson <andersca@mac.com>
Fri, 19 Dec 2008 20:58:05 +0000 (20:58 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@61260 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/Expr.h
lib/AST/Expr.cpp
lib/AST/ExprConstant.cpp
lib/Sema/SemaDecl.cpp

index d3bf1b96d641c620951597c6b9b7eceeb8c83734..2f2ca04947c6e54d47ffd0a6f13cdc23184b8df3 100644 (file)
@@ -208,9 +208,6 @@ public:
   /// 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;
index c01c973cf592548adeedc52ccd6019cd4f2f3afd..8aaea7ac9f3b716755bfdae27e6f42407520d6c1 100644 (file)
@@ -763,9 +763,11 @@ bool Expr::isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx,
     // 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.
       }
     }
index 7a83d6c063dad62c0868ca0073a807bfbeaeafa7..681016793f9dc4f8dbc13a38d9e994fa6c39e192 100644 (file)
@@ -1194,19 +1194,6 @@ bool Expr::Evaluate(EvalResult &Result, ASTContext &Ctx) const {
   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 @@ bool Expr::isEvaluatable(ASTContext &Ctx) const {
 }
 
 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();
 }
index 6c1af5f878786e27c8c0eafa163f4c6b8ea0125b..86af21024b636cfd0cde473181cfe8849cb53021 100644 (file)
@@ -1888,8 +1888,9 @@ bool Sema::CheckArithmeticConstantExpression(const Expr* Init) {
     // 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 @@ bool Sema::CheckArithmeticConstantExpression(const Expr* Init) {
     
     // 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 @@ static QualType TryToFixInvalidVariablyModifiedType(QualType T,
   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);