diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp index a01832f2ee9acba3bd93319ee0cbcdd89dcaa8b1..b004bde7bd286a339d350b6ce99ff784184e81da 100644 --- a/clang/lib/AST/Expr.cpp +++ b/clang/lib/AST/Expr.cpp @@ -720,6 +720,9 @@ bool Expr::isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx, Result.setIsUnsigned(!getType()->isSignedIntegerType()); break; } + case CXXZeroInitValueExprClass: + Result.clear(); + break; case TypesCompatibleExprClass: { const TypesCompatibleExpr *TCE = cast(this); Result.zextOrTrunc(static_cast(Ctx.getTypeSize(getType()))); diff --git a/clang/lib/CodeGen/CGExprComplex.cpp b/clang/lib/CodeGen/CGExprComplex.cpp index ba384e7f4ff65f5a94fb117548c71d47a6704143..3e1f695c79e92c3a7b33475391e23d11dc9f68d2 100644 --- a/clang/lib/CodeGen/CGExprComplex.cpp +++ b/clang/lib/CodeGen/CGExprComplex.cpp @@ -124,6 +124,12 @@ public: ComplexPairTy VisitCXXDefaultArgExpr(CXXDefaultArgExpr *DAE) { return Visit(DAE->getExpr()); } + ComplexPairTy VisitCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) { + assert(E->getType()->isAnyComplexType() && "Expected complex type!"); + QualType Elem = E->getType()->getAsComplexType()->getElementType(); + llvm::Constant *Null = llvm::Constant::getNullValue(CGF.ConvertType(Elem)); + return ComplexPairTy(Null, Null); + } struct BinOpInfo { ComplexPairTy LHS; diff --git a/clang/lib/CodeGen/CGExprConstant.cpp b/clang/lib/CodeGen/CGExprConstant.cpp index fe9b5c951354540e0742fc52e2cd6ddeb98afffb..9f94d4244f07883e44fdf1c7f2aa832ddf06078e 100644 --- a/clang/lib/CodeGen/CGExprConstant.cpp +++ b/clang/lib/CodeGen/CGExprConstant.cpp @@ -61,6 +61,9 @@ public: llvm::Constant *VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *E) { return llvm::ConstantInt::get(ConvertType(E->getType()), E->getValue()); } + llvm::Constant *VisitCXXZeroInitValueExpr(const CXXZeroInitValueExpr *E) { + return llvm::Constant::getNullValue(ConvertType(E->getType())); + } llvm::Constant *VisitObjCStringLiteral(const ObjCStringLiteral *E) { std::string S(E->getString()->getStrData(), E->getString()->getByteLength()); diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp index 3f7b7377523fdd0b304c76e2569ebc79093bece8..af8fe2779b214460877b3cebf3dbc9732702d794 100644 --- a/clang/lib/CodeGen/CGExprScalar.cpp +++ b/clang/lib/CodeGen/CGExprScalar.cpp @@ -109,6 +109,9 @@ public: Value *VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *E) { return llvm::ConstantInt::get(ConvertType(E->getType()), E->getValue()); } + Value *VisitCXXZeroInitValueExpr(const CXXZeroInitValueExpr *E) { + return llvm::Constant::getNullValue(ConvertType(E->getType())); + } Value *VisitTypesCompatibleExpr(const TypesCompatibleExpr *E) { return llvm::ConstantInt::get(ConvertType(E->getType()), CGF.getContext().typesAreCompatible( diff --git a/clang/test/CodeGen/cxx-value-init.cpp b/clang/test/CodeGen/cxx-value-init.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b1cddd913fbe5e2eac2e0f545d891dd88fc4a0fa --- /dev/null +++ b/clang/test/CodeGen/cxx-value-init.cpp @@ -0,0 +1,11 @@ +// RUN: clang -emit-llvm %s -o %t + +enum E {}; +int v1 = E(); +float v2 = float(); + +void f() { + int v3 = int(); + _Complex int v4 = typeof(_Complex int)(); + _Complex float v5 = typeof(_Complex float)(); +}