Author: ygao Date: Fri Jan 24 13:28:24 2014 New Revision: 200031 URL: http://llvm.org/viewvc/llvm-project?rev=200031&view=rev Log: Fixing PR18510 by checking whether the non-virtual base of the derived class might have a smaller size as compared to the stand-alone type of the base class. This is possible when the derived class is packed and hence might have smaller alignment requirement than the base class.
Differential Revision: http://llvm-reviews.chandlerc.com/D2599 Added: cfe/trunk/test/CodeGenCXX/pragma-pack-3.cpp Modified: cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp Modified: cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp?rev=200031&r1=200030&r2=200031&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp (original) +++ cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp Fri Jan 24 13:28:24 2014 @@ -558,7 +558,12 @@ bool CGRecordLayoutBuilder::LayoutBase(c if (getTypeAlignment(subobjectType) > Alignment) return false; - AppendField(baseOffset, subobjectType); + if (LastLaidOutBase.NonVirtualSize < CharUnits::fromQuantity( + Types.getDataLayout().getStructLayout(subobjectType)->getSizeInBytes())) + AppendBytes(LastLaidOutBase.NonVirtualSize); + else + AppendField(baseOffset, subobjectType); + return true; } Added: cfe/trunk/test/CodeGenCXX/pragma-pack-3.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/pragma-pack-3.cpp?rev=200031&view=auto ============================================================================== --- cfe/trunk/test/CodeGenCXX/pragma-pack-3.cpp (added) +++ cfe/trunk/test/CodeGenCXX/pragma-pack-3.cpp Fri Jan 24 13:28:24 2014 @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 %s -triple=i686-apple-darwin10 -emit-llvm -o - | FileCheck %s + +struct Base { + char a; +}; + +struct Derived_1 : virtual Base +{ + char b; +}; + +#pragma pack(1) +struct Derived_2 : Derived_1 { + // CHECK: %struct.Derived_2 = type <{ [5 x i8], %struct.Base }> +}; + +Derived_2 x; _______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
