Author: rjmccall Date: Wed Nov 18 20:27:55 2015 New Revision: 253533 URL: http://llvm.org/viewvc/llvm-project?rev=253533&view=rev Log: Fix the emission of ARC-style ivar layouts in the fragile runtime to start at the offset of the first ivar instead of the rounded-up end of the superclass. The latter could include a large amount of tail padding because of a highly-aligned ivar, and subclass ivars can be laid out within that.
Modified: cfe/trunk/lib/CodeGen/CGObjCMac.cpp cfe/trunk/test/CodeGenObjC/mrc-weak.m Modified: cfe/trunk/lib/CodeGen/CGObjCMac.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCMac.cpp?rev=253533&r1=253532&r2=253533&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CGObjCMac.cpp (original) +++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp Wed Nov 18 20:27:55 2015 @@ -4927,7 +4927,7 @@ CGObjCCommonMac::BuildIvarLayout(const O // ARC layout strings only include the class's ivars. In non-fragile // runtimes, that means starting at InstanceStart, rounded up to word // alignment. In fragile runtimes, there's no InstanceStart, so it means - // starting at the end of the superclass, rounded up to word alignment. + // starting at the offset of the first ivar, rounded up to word alignment. // // MRC weak layout strings follow the ARC style. CharUnits baseOffset; @@ -4938,10 +4938,9 @@ CGObjCCommonMac::BuildIvarLayout(const O if (isNonFragileABI()) { baseOffset = beginOffset; // InstanceStart - } else if (auto superClass = OI->getSuperClass()) { - auto startOffset = - CGM.getContext().getASTObjCInterfaceLayout(superClass).getSize(); - baseOffset = startOffset; + } else if (!ivars.empty()) { + baseOffset = + CharUnits::fromQuantity(ComputeIvarBaseOffset(CGM, OMD, ivars[0])); } else { baseOffset = CharUnits::Zero(); } Modified: cfe/trunk/test/CodeGenObjC/mrc-weak.m URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/mrc-weak.m?rev=253533&r1=253532&r2=253533&view=diff ============================================================================== --- cfe/trunk/test/CodeGenObjC/mrc-weak.m (original) +++ cfe/trunk/test/CodeGenObjC/mrc-weak.m Wed Nov 18 20:27:55 2015 @@ -6,6 +6,26 @@ - (void) run; @end +// The ivars in HighlyAlignedSubclass should be placed in the tail-padding +// of the superclass. Ensure that they're still covered by layouts. +@interface HighlyAligned : Object { + __attribute__((aligned(32))) void *array[2]; +} +@end +// CHECK-MODERN: @"OBJC_IVAR_$_HighlyAlignedSubclass.ivar2" = global i64 24, +// CHECK-MODERN: @"OBJC_IVAR_$_HighlyAlignedSubclass.ivar" = global i64 16, +// CHECK-MODERN: @OBJC_CLASS_NAME_{{.*}} = {{.*}} c"\02\00" +// CHECK-MODERN: @"\01l_OBJC_CLASS_RO_$_HighlyAlignedSubclass" = {{.*}} { +// CHECK-FRAGILE: @OBJC_INSTANCE_VARIABLES_HighlyAlignedSubclass = {{.*}}, i32 8 }, {{.*}}, i32 12 }] +// CHECK-FRAGILE: @OBJC_CLASS_NAME_{{.*}} = {{.*}} c"\02\00" +// CHECK-FRAGILE: @OBJC_CLASS_HighlyAlignedSubclass +@interface HighlyAlignedSubclass : HighlyAligned { + __weak id ivar; + __weak id ivar2; +} +@end +@implementation HighlyAlignedSubclass @end + // CHECK-MODERN: @OBJC_CLASS_NAME_{{.*}} = {{.*}} c"\01\00" // CHECK-MODERN: @"\01l_OBJC_CLASS_RO_$_Foo" = {{.*}} { i32 772 // 772 == 0x304 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits