bviyer updated this revision to Diff 158392. bviyer added a comment. Forgot to pass the -emit-llvm to the test case.
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 -emit-llvm %s +// RUN: %clang_cc1 -std=c++14 -emit-llvm %s +// RUN: %clang_cc1 -std=c++17 -emit-llvm %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 @@ -2119,6 +2119,16 @@ 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); }
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 -emit-llvm %s +// RUN: %clang_cc1 -std=c++14 -emit-llvm %s +// RUN: %clang_cc1 -std=c++17 -emit-llvm %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 @@ -2119,6 +2119,16 @@ 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); }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits