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


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

Reply via email to