[PATCH] D49952: Check for NULL Destination-Type when creating ArrayConstant
Balaji Iyer via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 27 18:20:35 PDT 2018
bviyer created this revision.
bviyer added reviewers: arphaman, dexonsmith, ahatanak, rjmccall.
While emitting Array Constant, if the destination type is null-pointer, it will cause an assert. This patch will check if the destination type is null, and if so then it will just return nullptr as the array constant (not something that is derived from destination type).
A test case is also attached.
Repository:
rC Clang
https://reviews.llvm.org/D49952
Files:
lib/CodeGen/CGExprConstant.cpp
test/CodeGenCXX/empty-struct-init-list.cpp
Index: test/CodeGenCXX/empty-struct-init-list.cpp
===================================================================
--- /dev/null
+++ test/CodeGenCXX/empty-struct-init-list.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -std=c++11 %s
+// RUN: %clang_cc1 -std=c++14 %s
+// RUN: %clang_cc1 -std=c++17 %s
+// expected-no-diagnostics
+
+typedef struct { } a;
+
+typedef struct {
+ a b[];
+} c;
+c d{ };
Index: lib/CodeGen/CGExprConstant.cpp
===================================================================
--- lib/CodeGen/CGExprConstant.cpp
+++ lib/CodeGen/CGExprConstant.cpp
@@ -650,6 +650,8 @@
}
if (NonzeroLength == 0) {
+ if (DestType == nullptr)
+ return nullptr;
return llvm::ConstantAggregateZero::get(
CGM.getTypes().ConvertType(QualType(DestType, 0)));
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49952.157820.patch
Type: text/x-patch
Size: 796 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180728/781e7af9/attachment.bin>
More information about the cfe-commits
mailing list