diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index c5d84d74db80..a6b546ef9ef0 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -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()) { diff --git a/clang/test/CodeGenCXX/const-init.cpp b/clang/test/CodeGenCXX/const-init.cpp index 874b5f64e2ba..9cfce7ace86b 100644 --- a/clang/test/CodeGenCXX/const-init.cpp +++ b/clang/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; };