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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@95577 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp
index c5d84d7..a6b546e 100644
--- a/lib/CodeGen/CodeGenModule.cpp
+++ b/lib/CodeGen/CodeGenModule.cpp
@@ -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>()) {
diff --git a/test/CodeGenCXX/const-init.cpp b/test/CodeGenCXX/const-init.cpp
index 874b5f6..9cfce7a 100644
--- a/test/CodeGenCXX/const-init.cpp
+++ b/test/CodeGenCXX/const-init.cpp
@@ -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; };