diff options
Diffstat (limited to 'lib/CodeGen/CGExprConstant.cpp')
-rw-r--r-- | lib/CodeGen/CGExprConstant.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/CodeGen/CGExprConstant.cpp b/lib/CodeGen/CGExprConstant.cpp index c0b7045a52..d7dfa253ad 100644 --- a/lib/CodeGen/CGExprConstant.cpp +++ b/lib/CodeGen/CGExprConstant.cpp @@ -742,6 +742,22 @@ public: } llvm::Constant *VisitInitListExpr(InitListExpr *ILE) { + if (ILE->getType()->isAnyComplexType() && ILE->getNumInits() == 2) { + // Complex type with element initializers + Expr *Real = ILE->getInit(0); + Expr *Imag = ILE->getInit(1); + llvm::Constant *Complex[2]; + Complex[0] = CGM.EmitConstantExpr(Real, Real->getType(), CGF); + if (!Complex[0]) + return 0; + Complex[1] = CGM.EmitConstantExpr(Imag, Imag->getType(), CGF); + if (!Complex[1]) + return 0; + llvm::StructType *STy = + cast<llvm::StructType>(ConvertType(ILE->getType())); + return llvm::ConstantStruct::get(STy, Complex); + } + if (ILE->getType()->isScalarType()) { // We have a scalar in braces. Just use the first element. if (ILE->getNumInits() > 0) { |