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


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)));
   }
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to