diff options
author | Douglas Gregor <dgregor@apple.com> | 2010-08-22 16:15:35 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2010-08-22 16:15:35 +0000 |
commit | 630c76efb0e40498d8d8fc27b0d237c82644cdf6 (patch) | |
tree | b4a96e88b8308ae7cadc355c7c5e2d2020c7ecfc /clang/lib/CodeGen/CGExprCXX.cpp | |
parent | fae824a32df7241749d9d030661807e65d8defa9 (diff) | |
download | bcm5719-llvm-630c76efb0e40498d8d8fc27b0d237c82644cdf6.tar.gz bcm5719-llvm-630c76efb0e40498d8d8fc27b0d237c82644cdf6.zip |
When performing value-initialization for a class with a non-trivial,
implicitly-defined default constructor, zero-initialize the memory
before calling the default constructor. Previously, we would only
zero-initialize in the case of a trivial default constructor.
Also, simplify the hideous logic that determines when we have a
trivial default constructor and, therefore, don't need to emit any
call at all.
llvm-svn: 111779
Diffstat (limited to 'clang/lib/CodeGen/CGExprCXX.cpp')
-rw-r--r-- | clang/lib/CodeGen/CGExprCXX.cpp | 34 |
1 files changed, 15 insertions, 19 deletions
diff --git a/clang/lib/CodeGen/CGExprCXX.cpp b/clang/lib/CodeGen/CGExprCXX.cpp index ad65b105f62..e8bc9b4f9aa 100644 --- a/clang/lib/CodeGen/CGExprCXX.cpp +++ b/clang/lib/CodeGen/CGExprCXX.cpp @@ -248,25 +248,18 @@ CodeGenFunction::EmitCXXConstructExpr(llvm::Value *Dest, const CXXConstructExpr *E) { assert(Dest && "Must have a destination!"); const CXXConstructorDecl *CD = E->getConstructor(); - const ConstantArrayType *Array = - getContext().getAsConstantArrayType(E->getType()); - // For a copy constructor, even if it is trivial, must fall thru so - // its argument is code-gen'ed. - if (!CD->isCopyConstructor()) { - QualType InitType = E->getType(); - if (Array) - InitType = getContext().getBaseElementType(Array); - const CXXRecordDecl *RD = - cast<CXXRecordDecl>(InitType->getAs<RecordType>()->getDecl()); - if (RD->hasTrivialConstructor()) { - // The constructor is trivial, but we may still need to zero-initialize - // the class. - if (E->requiresZeroInitialization()) - EmitNullInitialization(Dest, E->getType()); - - return; - } - } + + // If we require zero initialization before (or instead of) calling the + // constructor, as can be the case with a non-user-provided default + // constructor, emit the zero initialization now. + if (E->requiresZeroInitialization()) + EmitNullInitialization(Dest, E->getType()); + + + // If this is a call to a trivial default constructor, do nothing. + if (CD->isTrivial() && CD->isDefaultConstructor()) + return; + // Code gen optimization to eliminate copy constructor and return // its first argument instead, if in fact that argument is a temporary // object. @@ -276,6 +269,9 @@ CodeGenFunction::EmitCXXConstructExpr(llvm::Value *Dest, return; } } + + const ConstantArrayType *Array + = getContext().getAsConstantArrayType(E->getType()); if (Array) { QualType BaseElementTy = getContext().getBaseElementType(Array); const llvm::Type *BasePtr = ConvertType(BaseElementTy); |