From: Weverything Date: Fri, 14 Jan 2022 23:42:36 +0000 (-0800) Subject: Remove reference type when checking const structs X-Git-Tag: upstream/15.0.7~18646 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=be2147db054ec096199d1251bfab9065c7e0f29b;p=platform%2Fupstream%2Fllvm.git Remove reference type when checking const structs 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. Differential Revision: https://reviews.llvm.org/D117376 --- diff --git a/clang/lib/CodeGen/CGExprConstant.cpp b/clang/lib/CodeGen/CGExprConstant.cpp index cf1f2e0..ac4b4d1 100644 --- a/clang/lib/CodeGen/CGExprConstant.cpp +++ b/clang/lib/CodeGen/CGExprConstant.cpp @@ -851,6 +851,7 @@ bool ConstStructBuilder::Build(const APValue &Val, const RecordDecl *RD, } 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 index 0000000..76c6f29 --- /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({}); +}