[cfe-commits] r95577 - in /cfe/trunk: lib/CodeGen/CodeGenModule.cpp test/CodeGenCXX/const-init.cpp

John McCall rjmccall at apple.com
Mon Feb 8 13:46:50 PST 2010


Author: rjmccall
Date: Mon Feb  8 15:46:50 2010
New Revision: 95577

URL: http://llvm.org/viewvc/llvm-project?rev=95577&view=rev
Log:
Emit global references with constant initializers as constants.  Fixes PR5585.

The standard actually says that such references should have internal linkage,
but gcc doesn't do that, so we probably can't get away with it.


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

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Mon Feb  8 15:46:50 2010
@@ -783,7 +783,7 @@
 }
 
 static bool DeclIsConstantGlobal(ASTContext &Context, const VarDecl *D) {
-  if (!D->getType().isConstant(Context))
+  if (!D->getType().isConstant(Context) && !D->getType()->isReferenceType())
     return false;
   if (Context.getLangOptions().CPlusPlus &&
       Context.getBaseElementType(D->getType())->getAs<RecordType>()) {

Modified: cfe/trunk/test/CodeGenCXX/const-init.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/const-init.cpp?rev=95577&r1=95576&r2=95577&view=diff

==============================================================================
--- cfe/trunk/test/CodeGenCXX/const-init.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/const-init.cpp Mon Feb  8 15:46:50 2010
@@ -2,11 +2,11 @@
 
 // CHECK: @a = global i32 10
 int a = 10;
-// CHECK: @ar = global i32* @a
+// CHECK: @ar = constant i32* @a
 int &ar = a;
 
 void f();
-// CHECK: @fr = global void ()* @_Z1fv
+// CHECK: @fr = constant void ()* @_Z1fv
 void (&fr)() = f;
 
 struct S { int& a; };





More information about the cfe-commits mailing list