[CodeGen] IncompleteArray Support

Added code to support ArrayType that is not ConstantArray.

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

llvm-svn: 339207
This commit is contained in:
Balaji V. Iyer
2018-08-08 00:01:21 +00:00
parent 6504d4390f
commit 749e8285a5
2 changed files with 22 additions and 0 deletions

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

View File

@@ -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{ };