r339207 - [CodeGen] IncompleteArray Support
Balaji V. Iyer via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 7 17:01:21 PDT 2018
Author: bviyer
Date: Tue Aug 7 17:01:21 2018
New Revision: 339207
URL: http://llvm.org/viewvc/llvm-project?rev=339207&view=rev
Log:
[CodeGen] IncompleteArray Support
Added code to support ArrayType that is not ConstantArray.
https://reviews.llvm.org/D49952
rdar://42476155
Added:
cfe/trunk/test/CodeGenCXX/empty-struct-init-list.cpp
Modified:
cfe/trunk/lib/CodeGen/CGExprConstant.cpp
Modified: cfe/trunk/lib/CodeGen/CGExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprConstant.cpp?rev=339207&r1=339206&r2=339207&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprConstant.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprConstant.cpp Tue Aug 7 17:01:21 2018
@@ -1968,6 +1968,16 @@ llvm::Constant *ConstantEmitter::tryEmit
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);
}
Added: cfe/trunk/test/CodeGenCXX/empty-struct-init-list.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/empty-struct-init-list.cpp?rev=339207&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/empty-struct-init-list.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/empty-struct-init-list.cpp Tue Aug 7 17:01:21 2018
@@ -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{ };
More information about the cfe-commits
mailing list