[cfe-commits] r72463 - in /cfe/trunk: lib/AST/ExprConstant.cpp lib/CodeGen/CGExprConstant.cpp test/CodeGenCXX/references.cpp

Eli Friedman eli.friedman at gmail.com
Tue May 26 23:04:58 PDT 2009


Author: efriedma
Date: Wed May 27 01:04:58 2009
New Revision: 72463

URL: http://llvm.org/viewvc/llvm-project?rev=72463&view=rev
Log:
Fix up constant expression handling to deal with the address 
of a reference correctly.


Modified:
    cfe/trunk/lib/AST/ExprConstant.cpp
    cfe/trunk/lib/CodeGen/CGExprConstant.cpp
    cfe/trunk/test/CodeGenCXX/references.cpp

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=72463&r1=72462&r2=72463&view=diff

==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Wed May 27 01:04:58 2009
@@ -178,11 +178,20 @@
 }
 
 APValue LValueExprEvaluator::VisitDeclRefExpr(DeclRefExpr *E)
-{ 
+{
   if (!E->hasGlobalStorage())
     return APValue();
-  
-  return APValue(E, 0); 
+
+  if (isa<FunctionDecl>(E->getDecl())) {
+    return APValue(E, 0);
+  } else if (VarDecl* VD = dyn_cast<VarDecl>(E->getDecl())) {
+    if (!VD->getType()->isReferenceType())
+      return APValue(E, 0);
+    if (VD->getInit())
+      return Visit(VD->getInit());
+  }
+
+  return APValue();
 }
 
 APValue LValueExprEvaluator::VisitBlockExpr(BlockExpr *E)

Modified: cfe/trunk/lib/CodeGen/CGExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprConstant.cpp?rev=72463&r1=72462&r2=72463&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprConstant.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprConstant.cpp Wed May 27 01:04:58 2009
@@ -478,21 +478,9 @@
   
   bool Success = false;
   
-  if (DestType->isReferenceType()) {
-    // If the destination type is a reference type, we need to evaluate it
-    // as an lvalue.
-    if (E->EvaluateAsLValue(Result, Context)) {
-      if (const Expr *LVBase = Result.Val.getLValueBase()) {
-        if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(LVBase)) {
-          const ValueDecl *VD = cast<ValueDecl>(DRE->getDecl());
-
-          // We can only initialize a reference with an lvalue if the lvalue
-          // is not a reference itself.
-          Success = !VD->getType()->isReferenceType();
-        }
-      }
-    }
-  } else 
+  if (DestType->isReferenceType())
+    Success = E->EvaluateAsLValue(Result, Context);
+  else 
     Success = E->Evaluate(Result, Context);
   
   if (Success) {

Modified: cfe/trunk/test/CodeGenCXX/references.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/references.cpp?rev=72463&r1=72462&r2=72463&view=diff

==============================================================================
--- cfe/trunk/test/CodeGenCXX/references.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/references.cpp Wed May 27 01:04:58 2009
@@ -11,6 +11,7 @@
 
 int g;
 int& gr = g;
+int& grr = gr;
 void t3() {
   int b = gr;
 }





More information about the cfe-commits mailing list