]> granicus.if.org Git - clang/commitdiff
[CodeGen] IncompleteArray Support
authorBalaji V. Iyer <bviyer@gmail.com>
Wed, 8 Aug 2018 00:01:21 +0000 (00:01 +0000)
committerBalaji V. Iyer <bviyer@gmail.com>
Wed, 8 Aug 2018 00:01:21 +0000 (00:01 +0000)
Added code to support ArrayType that is not ConstantArray.

https://reviews.llvm.org/D49952
rdar://42476155

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@339207 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGExprConstant.cpp
test/CodeGenCXX/empty-struct-init-list.cpp [new file with mode: 0644]

index 68766479a539c5cb804c8a5b1bf8172e46d3955a..651b05a26f7f964c039f630327930aa6548b039d 100644 (file)
@@ -1968,6 +1968,16 @@ llvm::Constant *ConstantEmitter::tryEmitPrivate(const APValue &Value,
       Elts.push_back(C);
     }
 
+    // This means that the array type is probably "IncompleteType" or some
+    // type that is not ConstantArray.
+    if (CAT == nullptr && CommonElementType == nullptr && !NumInitElts) {
+      const ArrayType *AT = CGM.getContext().getAsArrayType(DestType);
+      CommonElementType = CGM.getTypes().ConvertType(AT->getElementType());
+      llvm::ArrayType *AType = llvm::ArrayType::get(CommonElementType,
+                                                    NumElements);
+      return llvm::ConstantAggregateZero::get(AType);
+    }
+
     return EmitArrayConstant(CGM, CAT, CommonElementType, NumElements, Elts,
                              Filler);
   }
diff --git a/test/CodeGenCXX/empty-struct-init-list.cpp b/test/CodeGenCXX/empty-struct-init-list.cpp
new file mode 100644 (file)
index 0000000..d1698b0
--- /dev/null
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -std=c++11 -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -std=c++14 -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -std=c++17 -emit-llvm -o - %s | FileCheck %s
+
+// CHECK: struct.a
+typedef struct { } a;
+typedef struct {
+  a b[];
+} c;
+
+// CHECK: global %struct.c zeroinitializer, align 1
+c d{ };