summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2015-11-19 02:27:55 +0000
committerJohn McCall <rjmccall@apple.com>2015-11-19 02:27:55 +0000
commitd80218fa4221c76fa1b822a406253921d4c7f8fc (patch)
tree175bcce0f7357453b5f5fe2994370e9e3a058135
parent61fcb521fa1dd3426b653818fd315f9e542fc12b (diff)
downloadbcm5719-llvm-d80218fa4221c76fa1b822a406253921d4c7f8fc.tar.gz
bcm5719-llvm-d80218fa4221c76fa1b822a406253921d4c7f8fc.zip
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. llvm-svn: 253533
-rw-r--r--clang/lib/CodeGen/CGObjCMac.cpp9
-rw-r--r--clang/test/CodeGenObjC/mrc-weak.m20
2 files changed, 24 insertions, 5 deletions
diff --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp
index a5f504e141c..dad172b5651 100644
--- a/clang/lib/CodeGen/CGObjCMac.cpp
+++ b/clang/lib/CodeGen/CGObjCMac.cpp
@@ -4927,7 +4927,7 @@ CGObjCCommonMac::BuildIvarLayout(const ObjCImplementationDecl *OMD,
// 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 ObjCImplementationDecl *OMD,
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();
}
diff --git a/clang/test/CodeGenObjC/mrc-weak.m b/clang/test/CodeGenObjC/mrc-weak.m
index f9c4ff1b123..9072b1a0832 100644
--- a/clang/test/CodeGenObjC/mrc-weak.m
+++ b/clang/test/CodeGenObjC/mrc-weak.m
@@ -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
OpenPOWER on IntegriCloud