diff options
| author | Anders Carlsson <andersca@mac.com> | 2010-05-22 17:35:42 +0000 |
|---|---|---|
| committer | Anders Carlsson <andersca@mac.com> | 2010-05-22 17:35:42 +0000 |
| commit | c0964b60e501872e35c51db23f5fe6a6a5523091 (patch) | |
| tree | 07a2ceb59aeb2463a21a30b0cc6ee40c64509bca /clang/lib/CodeGen/CodeGenFunction.cpp | |
| parent | 024d80e571ae0fc97ca731e0a56faac56f20841a (diff) | |
| download | llvm-c0964b60e501872e35c51db23f5fe6a6a5523091.zip llvm-c0964b60e501872e35c51db23f5fe6a6a5523091.tar.gz llvm-c0964b60e501872e35c51db23f5fe6a6a5523091.tar.bz2 | |
Re-land the fix for PR7139.
llvm-svn: 104446
Diffstat (limited to 'clang/lib/CodeGen/CodeGenFunction.cpp')
| -rw-r--r-- | clang/lib/CodeGen/CodeGenFunction.cpp | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index d3bf164..222dcc4 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -472,7 +472,23 @@ void CodeGenFunction::ErrorUnsupported(const Stmt *S, const char *Type, CGM.ErrorUnsupported(S, Type, OmitOnError); } -void CodeGenFunction::EmitMemSetToZero(llvm::Value *DestPtr, QualType Ty) { +void +CodeGenFunction::EmitNullInitialization(llvm::Value *DestPtr, QualType Ty) { + // If the type contains a pointer to data member we can't memset it to zero. + // Instead, create a null constant and copy it to the destination. + if (CGM.getTypes().ContainsPointerToDataMember(Ty)) { + llvm::Constant *NullConstant = CGM.EmitNullConstant(Ty); + + llvm::GlobalVariable *NullVariable = + new llvm::GlobalVariable(CGM.getModule(), NullConstant->getType(), + /*isConstant=*/true, + llvm::GlobalVariable::PrivateLinkage, + NullConstant, llvm::Twine()); + EmitAggregateCopy(DestPtr, NullVariable, Ty, /*isVolatile=*/false); + return; + } + + // Ignore empty classes in C++. if (getContext().getLangOptions().CPlusPlus) { if (const RecordType *RT = Ty->getAs<RecordType>()) { @@ -481,6 +497,9 @@ void CodeGenFunction::EmitMemSetToZero(llvm::Value *DestPtr, QualType Ty) { } } + // Otherwise, just memset the whole thing to zero. This is legal + // because in LLVM, all default initializers (other than the ones we just + // handled above) are guaranteed to have a bit pattern of all zeros. const llvm::Type *BP = llvm::Type::getInt8PtrTy(VMContext); if (DestPtr->getType() != BP) DestPtr = Builder.CreateBitCast(DestPtr, BP, "tmp"); |
