Don't copy or initialize empty classes. Fixes PR7012.

llvm-svn: 102891
This commit is contained in:
Anders Carlsson 2010-05-03 01:20:20 +00:00
parent 8bdbb5be19
commit 16e94af67c
3 changed files with 17 additions and 1 deletions

View File

@ -738,6 +738,14 @@ void CodeGenFunction::EmitAggregateCopy(llvm::Value *DestPtr,
bool isVolatile) {
assert(!Ty->isAnyComplexType() && "Shouldn't happen for complex");
// Ignore empty classes in C++.
if (getContext().getLangOptions().CPlusPlus) {
if (const RecordType *RT = Ty->getAs<RecordType>()) {
if (cast<CXXRecordDecl>(RT->getDecl())->isEmpty())
return;
}
}
// Aggregate assignment turns into llvm.memcpy. This is almost valid per
// C99 6.5.16.1p3, which states "If the value being stored in an object is
// read from another object that overlaps in anyway the storage of the first

View File

@ -473,6 +473,14 @@ void CodeGenFunction::ErrorUnsupported(const Stmt *S, const char *Type,
}
void CodeGenFunction::EmitMemSetToZero(llvm::Value *DestPtr, QualType Ty) {
// Ignore empty classes in C++.
if (getContext().getLangOptions().CPlusPlus) {
if (const RecordType *RT = Ty->getAs<RecordType>()) {
if (cast<CXXRecordDecl>(RT->getDecl())->isEmpty())
return;
}
}
const llvm::Type *BP = llvm::Type::getInt8PtrTy(VMContext);
if (DestPtr->getType() != BP)
DestPtr = Builder.CreateBitCast(DestPtr, BP, "tmp");

View File

@ -90,7 +90,7 @@ A* t10() {
return new(1, 2, 3.45, 100) A;
}
struct B { };
struct B { int a; };
void t11() {
// CHECK: call noalias i8* @_Znwm
// CHECK: call void @llvm.memset.p0i8.i64(