[cfe-commits] r102891 - in /cfe/trunk: lib/CodeGen/CGExprAgg.cpp lib/CodeGen/CodeGenFunction.cpp test/CodeGenCXX/new.cpp
Douglas Gregor
dgregor at apple.com
Sun May 2 21:20:26 PDT 2010
On May 2, 2010, at 6:20 PM, Anders Carlsson wrote:
> Author: andersca
> Date: Sun May 2 20:20:20 2010
> New Revision: 102891
>
> URL: http://llvm.org/viewvc/llvm-project?rev=102891&view=rev
> Log:
> Don't copy or initialize empty classes. Fixes PR7012.
No negative test case? (To make sure we aren't copying these bytes)?
- Doug
> Modified:
> cfe/trunk/lib/CodeGen/CGExprAgg.cpp
> cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
> cfe/trunk/test/CodeGenCXX/new.cpp
>
> Modified: cfe/trunk/lib/CodeGen/CGExprAgg.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprAgg.cpp?rev=102891&r1=102890&r2=102891&view=diff
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CGExprAgg.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGExprAgg.cpp Sun May 2 20:20:20 2010
> @@ -738,6 +738,14 @@
> 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
>
> Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=102891&r1=102890&r2=102891&view=diff
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp Sun May 2 20:20:20 2010
> @@ -473,6 +473,14 @@
> }
>
> 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");
>
> Modified: cfe/trunk/test/CodeGenCXX/new.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/new.cpp?rev=102891&r1=102890&r2=102891&view=diff
> ==============================================================================
> --- cfe/trunk/test/CodeGenCXX/new.cpp (original)
> +++ cfe/trunk/test/CodeGenCXX/new.cpp Sun May 2 20:20:20 2010
> @@ -90,7 +90,7 @@
> 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(
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
More information about the cfe-commits
mailing list