]> granicus.if.org Git - clang/commitdiff
Emit global references with constant initializers as constants. Fixes PR5585.
authorJohn McCall <rjmccall@apple.com>
Mon, 8 Feb 2010 21:46:50 +0000 (21:46 +0000)
committerJohn McCall <rjmccall@apple.com>
Mon, 8 Feb 2010 21:46:50 +0000 (21:46 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@95577 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CodeGenModule.cpp
test/CodeGenCXX/const-init.cpp

index c5d84d74db80e7a07b7cbcc453a7e2a6b40f0e97..a6b546ef9ef04a45e574b63fc47d952c45e84cd6 100644 (file)
@@ -783,7 +783,7 @@ CodeGenModule::CreateRuntimeFunction(const llvm::FunctionType *FTy,
 }
 
 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>()) {
index 874b5f64e2ba05e895aeb50dd6a7a4d1b98e7dfe..9cfce7ace86b6e55bc719a7e89383bd0dc5e6ce4 100644 (file)
@@ -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; };