This revision was automatically updated to reflect the committed changes.
Closed by commit rG6796053723a6: [CodeGen] Fix the type of the constant that is
used to zero-initialize a (authored by ahatanak).
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);
}
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);
}
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits