[PATCH] D117376: Remove reference type when checking const structs

Richard Trieu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 28 13:22:21 PST 2022


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbe2147db054e: Remove reference type when checking const structs (authored by rtrieu).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D117376/new/

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());


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D117376.404149.patch
Type: text/x-patch
Size: 942 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220128/c87369be/attachment.bin>


More information about the cfe-commits mailing list