[cfe-commits] r103780 - in /cfe/trunk: include/clang/AST/Expr.h lib/AST/ExprConstant.cpp

Abramo Bagnara abramo.bagnara at gmail.com
Fri May 14 10:07:14 PDT 2010


Author: abramo
Date: Fri May 14 12:07:14 2010
New Revision: 103780

URL: http://llvm.org/viewvc/llvm-project?rev=103780&view=rev
Log:
Added Expr::EvaluateAsAnyLValue.

Modified:
    cfe/trunk/include/clang/AST/Expr.h
    cfe/trunk/lib/AST/ExprConstant.cpp

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=103780&r1=103779&r2=103780&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Fri May 14 12:07:14 2010
@@ -248,6 +248,15 @@
     SourceLocation DiagLoc;
 
     EvalResult() : HasSideEffects(false), Diag(0), DiagExpr(0) {}
+
+    // isGlobalLValue - Return true if the evaluated lvalue expression
+    // is global.
+    bool isGlobalLValue() const;
+    // hasSideEffects - Return true if the evaluated expression has
+    // side effects.
+    bool hasSideEffects() const {
+      return HasSideEffects;
+    }
   };
 
   /// Evaluate - Return true if this is a constant which we can fold using
@@ -279,6 +288,9 @@
   /// with link time known address.
   bool EvaluateAsLValue(EvalResult &Result, ASTContext &Ctx) const;
 
+  /// EvaluateAsLValue - Evaluate an expression to see if it's a lvalue.
+  bool EvaluateAsAnyLValue(EvalResult &Result, ASTContext &Ctx) const;
+
   /// \brief Enumeration used to describe how \c isNullPointerConstant()
   /// should cope with value-dependent expressions.
   enum NullPointerConstantValueDependence {

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=103780&r1=103779&r2=103780&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Fri May 14 12:07:14 2010
@@ -106,8 +106,7 @@
 // Misc utilities
 //===----------------------------------------------------------------------===//
 
-static bool IsGlobalLValue(LValue &Value) {
-  const Expr *E = Value.Base;
+static bool IsGlobalLValue(const Expr* E) {
   if (!E) return true;
 
   if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E)) {
@@ -135,7 +134,7 @@
   }
 
   // Require the base expression to be a global l-value.
-  if (!IsGlobalLValue(Value)) return false;
+  if (!IsGlobalLValue(Base)) return false;
 
   // We have a non-null base expression.  These are generally known to
   // be true, but if it'a decl-ref to a weak symbol it can be null at
@@ -2187,7 +2186,7 @@
     LValue LV;
     if (!EvaluatePointer(E, LV, Info))
       return false;
-    if (!IsGlobalLValue(LV))
+    if (!IsGlobalLValue(LV.Base))
       return false;
     LV.moveInto(Info.EvalResult.Val);
   } else if (E->getType()->isRealFloatingType()) {
@@ -2220,7 +2219,18 @@
   LValue LV;
   if (EvaluateLValue(this, LV, Info) &&
       !Result.HasSideEffects &&
-      IsGlobalLValue(LV)) {
+      IsGlobalLValue(LV.Base)) {
+    LV.moveInto(Result.Val);
+    return true;
+  }
+  return false;
+}
+
+bool Expr::EvaluateAsAnyLValue(EvalResult &Result, ASTContext &Ctx) const {
+  EvalInfo Info(Ctx, Result);
+
+  LValue LV;
+  if (EvaluateLValue(this, LV, Info)) {
     LV.moveInto(Result.Val);
     return true;
   }
@@ -2250,6 +2260,12 @@
   return EvalResult.Val.getInt();
 }
 
+ bool Expr::EvalResult::isGlobalLValue() const {
+   assert(Val.isLValue());
+   return IsGlobalLValue(Val.getLValueBase());
+ }
+
+
 /// isIntegerConstantExpr - this recursive routine will test if an expression is
 /// an integer constant expression.
 





More information about the cfe-commits mailing list