rtrieu created this revision. rtrieu added reviewers: rsmith, cfe-commits. rtrieu requested review of this revision. Herald added a project: clang.
ConstStructBuilder::Finalize in CGExprConstant.ccp assumes that the passed in QualType is a RecordType. In some instances, the type is a reference to a RecordType and the reference needs to be removed first. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D117376 Files: clang/lib/CodeGen/CGExprConstant.cpp clang/test/CodeGenCXX/merge-all-constants-references.cpp Index: clang/test/CodeGenCXX/merge-all-constants-references.cpp =================================================================== --- /dev/null +++ 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({}); +} Index: clang/lib/CodeGen/CGExprConstant.cpp =================================================================== --- clang/lib/CodeGen/CGExprConstant.cpp +++ clang/lib/CodeGen/CGExprConstant.cpp @@ -851,6 +851,7 @@ } llvm::Constant *ConstStructBuilder::Finalize(QualType Type) { + Type = Type.getNonReferenceType(); RecordDecl *RD = Type->castAs<RecordType>()->getDecl(); llvm::Type *ValTy = CGM.getTypes().ConvertType(Type); return Builder.build(ValTy, RD->hasFlexibleArrayMember());
Index: clang/test/CodeGenCXX/merge-all-constants-references.cpp =================================================================== --- /dev/null +++ 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({}); +} Index: clang/lib/CodeGen/CGExprConstant.cpp =================================================================== --- clang/lib/CodeGen/CGExprConstant.cpp +++ clang/lib/CodeGen/CGExprConstant.cpp @@ -851,6 +851,7 @@ } llvm::Constant *ConstStructBuilder::Finalize(QualType Type) { + Type = Type.getNonReferenceType(); RecordDecl *RD = Type->castAs<RecordType>()->getDecl(); llvm::Type *ValTy = CGM.getTypes().ConvertType(Type); return Builder.build(ValTy, RD->hasFlexibleArrayMember());
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits