[PATCH] D151172: [CodeGen] Fix the type of the constant that is used to zero-initialize a flexible array member
Akira Hatanaka via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue May 23 08:58:41 PDT 2023
ahatanak updated this revision to Diff 524746.
ahatanak added a comment.
Fix the desired type of incomplete arrays that is passed to `EmitArrayConstant`.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D151172/new/
https://reviews.llvm.org/D151172
Files:
clang/lib/CodeGen/CGExprConstant.cpp
clang/test/CodeGenCXX/flexible-array-init.cpp
Index: clang/test/CodeGenCXX/flexible-array-init.cpp
===================================================================
--- clang/test/CodeGenCXX/flexible-array-init.cpp
+++ clang/test/CodeGenCXX/flexible-array-init.cpp
@@ -23,3 +23,14 @@
struct B { int x; char y; char z[]; };
B e = {f(), f(), f(), f()}; // expected-error {{cannot compile this flexible array initializer yet}}
#endif
+
+namespace zero_initializer {
+A a0{0, 0}, a1{0, {0, 0}};
+// CHECK: @_ZN16zero_initializer2a0E = global { i32, [1 x i32] } zeroinitializer,
+// CHECK: @_ZN16zero_initializer2a1E = global { i32, [2 x i32] } zeroinitializer,
+
+struct S { int x[]; };
+
+S s{0};
+// CHECK: @_ZN16zero_initializer1sE = global { [1 x i32] } zeroinitializer,
+}
Index: clang/lib/CodeGen/CGExprConstant.cpp
===================================================================
--- clang/lib/CodeGen/CGExprConstant.cpp
+++ clang/lib/CodeGen/CGExprConstant.cpp
@@ -2189,6 +2189,11 @@
llvm::ArrayType *Desired =
cast<llvm::ArrayType>(CGM.getTypes().ConvertType(DestType));
+
+ // Fix the type of incomplete arrays if the initializer isn't empty.
+ if (DestType->isIncompleteArrayType() && !Elts.empty())
+ Desired = llvm::ArrayType::get(Desired->getElementType(), Elts.size());
+
return EmitArrayConstant(CGM, Desired, CommonElementType, NumElements, Elts,
Filler);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D151172.524746.patch
Type: text/x-patch
Size: 1398 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230523/69f8c5c9/attachment.bin>
More information about the cfe-commits
mailing list