diff --git a/clang/lib/CodeGen/CGExprConstant.cpp b/clang/lib/CodeGen/CGExprConstant.cpp --- a/clang/lib/CodeGen/CGExprConstant.cpp +++ b/clang/lib/CodeGen/CGExprConstant.cpp @@ -851,6 +851,7 @@ } llvm::Constant *ConstStructBuilder::Finalize(QualType Type) { + Type = Type.getNonReferenceType(); RecordDecl *RD = Type->castAs()->getDecl(); llvm::Type *ValTy = CGM.getTypes().ConvertType(Type); return Builder.build(ValTy, RD->hasFlexibleArrayMember()); diff --git a/clang/test/CodeGenCXX/merge-all-constants-references.cpp b/clang/test/CodeGenCXX/merge-all-constants-references.cpp new file mode 100644 --- /dev/null +++ b/clang/test/CodeGenCXX/merge-all-constants-references.cpp @@ -0,0 +1,14 @@ +// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -fmerge-all-constants %s -o /dev/null + +struct A { +}; + +struct B { + const struct A& a = {}; +}; + +void Test(const struct B&); + +void Run() { + Test({}); +}