[cfe-commits] r151922 - in /cfe/trunk: lib/CodeGen/CGExprScalar.cpp test/CodeGenCXX/const-init-cxx11.cpp

Daniel Dunbar daniel at zuster.org
Fri Mar 2 08:24:25 PST 2012


Author: ddunbar
Date: Fri Mar  2 10:24:25 2012
New Revision: 151922

URL: http://llvm.org/viewvc/llvm-project?rev=151922&view=rev
Log:
Revert r151879, r151880, "PR12145: Avoid emitting loads of constexpr variables in contexts where there" and "Fix buildbot: make this test less dependent on the value names in the produced IR."

They broke bootstrap.

Modified:
    cfe/trunk/lib/CodeGen/CGExprScalar.cpp
    cfe/trunk/test/CodeGenCXX/const-init-cxx11.cpp

Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=151922&r1=151921&r2=151922&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Fri Mar  2 10:24:25 2012
@@ -212,21 +212,18 @@
   // l-values.
   Value *VisitDeclRefExpr(DeclRefExpr *E) {
     Expr::EvalResult Result;
-    bool IsReferenceConstant = false;
-    QualType EvalTy = E->getType();
-    if (!E->EvaluateAsRValue(Result, CGF.getContext())) {
-      // If this is a reference, try to determine what it is bound to.
-      if (!E->getDecl()->getType()->isReferenceType() ||
-          !E->EvaluateAsLValue(Result, CGF.getContext()))
-        return EmitLoadOfLValue(E);
-
-      IsReferenceConstant = true;
-      EvalTy = E->getDecl()->getType();
-    }
+    if (!E->EvaluateAsRValue(Result, CGF.getContext()))
+      return EmitLoadOfLValue(E);
 
     assert(!Result.HasSideEffects && "Constant declref with side-effect?!");
 
-    llvm::Constant *C = CGF.CGM.EmitConstantValue(Result.Val, EvalTy, &CGF);
+    llvm::Constant *C;
+    if (Result.Val.isInt())
+      C = Builder.getInt(Result.Val.getInt());
+    else if (Result.Val.isFloat())
+      C = llvm::ConstantFP::get(VMContext, Result.Val.getFloat());
+    else
+      return EmitLoadOfLValue(E);
 
     // Make sure we emit a debug reference to the global variable.
     if (VarDecl *VD = dyn_cast<VarDecl>(E->getDecl())) {
@@ -236,9 +233,6 @@
       CGF.EmitDeclRefExprDbgValue(E, C);
     }
 
-    if (IsReferenceConstant)
-      return EmitLoadOfLValue(CGF.MakeNaturalAlignAddrLValue(C, E->getType()));
-
     return C;
   }
   Value *VisitObjCSelectorExpr(ObjCSelectorExpr *E) {

Modified: cfe/trunk/test/CodeGenCXX/const-init-cxx11.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/const-init-cxx11.cpp?rev=151922&r1=151921&r2=151922&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/const-init-cxx11.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/const-init-cxx11.cpp Fri Mar  2 10:24:25 2012
@@ -337,30 +337,3 @@
   X<D> x;
   // CHECK: call {{.*}}@_ZN11VirtualBase1XINS_1DEEC1Ev
 }
-
-// PR12145
-namespace Unreferenced {
-  int n;
-  constexpr int *p = &n;
-  // We must not emit a load of 'p' here, since it's not odr-used.
-  int q = *p;
-  // CHECK-NOT: _ZN12Unreferenced1pE
-  // CHECK: = load i32* @_ZN12Unreferenced1nE
-  // CHECK-NEXT: store i32 {{.*}}, i32* @_ZN12Unreferenced1qE
-  // CHECK-NOT: _ZN12Unreferenced1pE
-
-  // Technically, we are not required to substitute variables of reference types
-  // initialized by constant expressions, because the special case for odr-use
-  // of variables in [basic.def.odr]p2 only applies to objects. But we do so
-  // anyway.
-
-  constexpr int &r = n;
-  // CHECK-NOT: _ZN12Unreferenced1rE
-  int s = r;
-
-  const int t = 1;
-  const int &rt = t;
-  int f(int);
-  int u = f(rt);
-  // CHECK: call i32 @_ZN12Unreferenced1fEi(i32 1)
-}





More information about the cfe-commits mailing list