]> granicus.if.org Git - clang/commitdiff
NeXT: Set alignment on a number of ObjC metadata variables (matching llvm-gcc).
authorDaniel Dunbar <daniel@zuster.org>
Mon, 9 Mar 2009 22:18:41 +0000 (22:18 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Mon, 9 Mar 2009 22:18:41 +0000 (22:18 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66481 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGObjCMac.cpp
test/CodeGenObjC/objc-align.m [new file with mode: 0644]

index 454f6633111a9a5adff5cc9420a13ea1fb0dc2e4..d33005ef0c8a118b61a3699954ffeea773af956a 100644 (file)
@@ -1086,6 +1086,7 @@ llvm::Constant *CGObjCMac::GetOrEmitProtocol(const ObjCProtocolDecl *PD) {
                                std::string("\01L_OBJC_PROTOCOL_")+ProtocolName,
                                &CGM.getModule());
     Entry->setSection("__OBJC,__protocol,regular,no_dead_strip");
+    Entry->setAlignment(4);
     UsedGlobals.push_back(Entry);
     // FIXME: Is this necessary? Why only for protocol?
     Entry->setAlignment(4);
@@ -1108,6 +1109,7 @@ llvm::Constant *CGObjCMac::GetOrEmitProtocolRef(const ObjCProtocolDecl *PD) {
                                "\01L_OBJC_PROTOCOL_" + PD->getNameAsString(),
                                &CGM.getModule());
     Entry->setSection("__OBJC,__protocol,regular,no_dead_strip");
+    Entry->setAlignment(4);
     UsedGlobals.push_back(Entry);
     // FIXME: Is this necessary? Why only for protocol?
     Entry->setAlignment(4);
@@ -1195,7 +1197,7 @@ CGObjCMac::EmitProtocolList(const std::string &Name,
   llvm::Constant *Init = llvm::ConstantStruct::get(Values);
   llvm::GlobalVariable *GV = 
     CreateMetadataVar(Name, Init, "__OBJC,__cat_cls_meth,regular,no_dead_strip",
-                      0, false);
+                      4, false);
   return llvm::ConstantExpr::getBitCast(GV, ObjCTypes.ProtocolListPtrTy);
 }
 
@@ -1354,7 +1356,7 @@ void CGObjCMac::GenerateCategory(const ObjCCategoryImplDecl *OCD) {
   llvm::GlobalVariable *GV = 
     CreateMetadataVar(std::string("\01L_OBJC_CATEGORY_")+ExtName, Init,
                       "__OBJC,__category,regular,no_dead_strip",
-                      0, true);
+                      4, true);
   DefinedCategories.push_back(GV);
 }
 
@@ -1489,8 +1491,7 @@ void CGObjCMac::GenerateClass(const ObjCImplementationDecl *ID) {
   llvm::GlobalVariable *GV = 
     CreateMetadataVar(std::string("\01L_OBJC_CLASS_")+ClassName, Init,
                       "__OBJC,__class,regular,no_dead_strip",
-                      32, // FIXME: Why?
-                      true);
+                      4, true);
   DefinedClasses.push_back(GV);
 }
 
@@ -1559,9 +1560,8 @@ llvm::Constant *CGObjCMac::EmitMetaClass(const ObjCImplementationDecl *ID,
                                   &CGM.getModule());
   }
   GV->setSection("__OBJC,__meta_class,regular,no_dead_strip");
+  GV->setAlignment(4);
   UsedGlobals.push_back(GV);
-  // FIXME: Why?
-  GV->setAlignment(32);
 
   return GV;
 }
@@ -1715,8 +1715,8 @@ llvm::Constant *CGObjCMac::EmitIvarList(const ObjCImplementationDecl *ID,
   llvm::GlobalVariable *GV;
   if (ForClass)
     GV = CreateMetadataVar("\01L_OBJC_CLASS_VARIABLES_" + ID->getNameAsString(),
-                           Init, "__OBJC,__cls_vars,regular,no_dead_strip", 
-                           32, true);
+                           Init, "__OBJC,__class_vars,regular,no_dead_strip", 
+                           4, true);
   else
     GV = CreateMetadataVar("\01L_OBJC_INSTANCE_VARIABLES_"
                            + ID->getNameAsString(),
@@ -2349,7 +2349,7 @@ void CGObjCMac::EmitModuleInfo() {
   CreateMetadataVar("\01L_OBJC_MODULES", 
                     llvm::ConstantStruct::get(ObjCTypes.ModuleTy, Values),
                     "__OBJC,__module_info,regular,no_dead_strip",
-                    0, true);
+                    4, true);
 }
 
 llvm::Constant *CGObjCMac::EmitModuleSymbols() {
@@ -3493,8 +3493,7 @@ void CGObjCNonFragileABIMac::FinishNonFragileABIModule() {
                                Init,
                                "\01L_OBJC_LABEL_CLASS_$",
                                &CGM.getModule());
-    GV->setAlignment(
-      CGM.getTargetData().getPrefTypeAlignment(ObjCTypes.Int8PtrTy));
+    GV->setAlignment(8);
     GV->setSection("__DATA, __objc_classlist, regular, no_dead_strip");
     UsedGlobals.push_back(GV);
   }
@@ -3521,6 +3520,7 @@ void CGObjCNonFragileABIMac::FinishNonFragileABIModule() {
                                Init,
                                "\01L_OBJC_LABEL_CATEGORY_$",
                                &CGM.getModule());
+    GV->setAlignment(8);
     GV->setSection("__DATA, __objc_catlist, regular, no_dead_strip");
     UsedGlobals.push_back(GV);
   }
diff --git a/test/CodeGenObjC/objc-align.m b/test/CodeGenObjC/objc-align.m
new file mode 100644 (file)
index 0000000..33d7f30
--- /dev/null
@@ -0,0 +1,47 @@
+// 32-bit
+
+// RUNX: llvm-gcc -m32 -emit-llvm -S -o %t %s &&
+// RUN: clang -triple i386-apple-darwin9 -emit-llvm -o %t %s &&
+// RUN: grep '@"\\01L_OBJC_CATEGORY_A_Cat" = internal global .*, section "__OBJC,__category,regular,no_dead_strip", align 4' %t &&
+// RUN: grep '@"\\01L_OBJC_CLASS_A" = internal global .*, section "__OBJC,__class,regular,no_dead_strip", align 4' %t &&
+// RUN: grep '@"\\01L_OBJC_CLASS_C" = internal global .*, section "__OBJC,__class,regular,no_dead_strip", align 4' %t &&
+// RUN: grep '@"\\01L_OBJC_CLASS_PROTOCOLS_C" = internal global .*, section "__OBJC,__cat_cls_meth,regular,no_dead_strip", align 4' %t &&
+// RUN: grep '@"\\01L_OBJC_IMAGE_INFO" = internal constant .*, section "__OBJC, __image_info,regular"' %t &&
+// RUN: grep '@"\\01L_OBJC_METACLASS_A" = internal global .*, section "__OBJC,__meta_class,regular,no_dead_strip", align 4' %t &&
+// RUN: grep '@"\\01L_OBJC_METACLASS_C" = internal global .*, section "__OBJC,__meta_class,regular,no_dead_strip", align 4' %t &&
+// RUN: grep '@"\\01L_OBJC_MODULES" = internal global .*, section "__OBJC,__module_info,regular,no_dead_strip", align 4' %t &&
+// RUN: grep '@"\\01L_OBJC_PROTOCOL_P" = internal global .*, section "__OBJC,__protocol,regular,no_dead_strip", align 4' %t &&
+
+// 64-bit
+
+// RUNX: clang -triple i386-apple-darwin9 -emit-llvm -o %t %s &&
+// RUNX: grep '@"OBJC_CLASS_$_A" = global' %t &&
+// RUNX: grep '@"OBJC_CLASS_$_C" = global' %t &&
+// RUNX: grep '@"OBJC_METACLASS_$_A" = global' %t &&
+// RUNX: grep '@"OBJC_METACLASS_$_C" = global' %t &&
+// RUNX: grep '@"\\01L_OBJC_CLASSLIST_REFERENCES_$_0" = internal global .*, section "__DATA, __objc_classrefs, regular, no_dead_strip", align 8' %t &&
+// RUNX: grep '@"\\01L_OBJC_IMAGE_INFO" = internal constant .*, section "__DATA, __objc_imageinfo, regular, no_dead_strip"' %t &&
+// RUNX: grep '@"\\01L_OBJC_LABEL_CATEGORY_$" = internal global .*, section "__DATA, __objc_catlist, regular, no_dead_strip", align 8' %t &&
+// RUNX: grep '@"\\01L_OBJC_LABEL_CLASS_$" = internal global .*, section "__DATA, __objc_classlist, regular, no_dead_strip", align 8' %t &&
+// RUNX: grep '@"\\01l_OBJC_$_CATEGORY_A_$_Cat" = internal global .*, section "__DATA, __objc_const", align 8' %t &&
+// RUNX: grep '@"\\01l_OBJC_CLASS_PROTOCOLS_$_C" = internal global .*, section "__DATA, __objc_const", align 8' %t &&
+// RUNX: grep '@"\\01l_OBJC_CLASS_RO_$_A" = internal global .*, section "__DATA, __objc_const", align 8' %t &&
+// RUNX: grep '@"\\01l_OBJC_CLASS_RO_$_C" = internal global .*, section "__DATA, __objc_const", align 8' %t &&
+// RUNX: grep '@"\\01l_OBJC_LABEL_PROTOCOL_$_P" = weak hidden global .*, section "__DATA, __objc_protolist, coalesced, no_dead_strip", align 8' %t &&
+// RUNX: grep '@"\\01l_OBJC_METACLASS_RO_$_A" = internal global .*, section "__DATA, __objc_const", align 8' %t &&
+// RUNX: grep '@"\\01l_OBJC_METACLASS_RO_$_C" = internal global .*, section "__DATA, __objc_const", align 8' %t &&
+// RUNX: grep '@"\\01l_OBJC_PROTOCOL_$_P" = weak hidden global .*, section "__DATA,__datacoal_nt,coalesced", align 8' %t &&
+
+// RUN: true
+
+@interface A @end
+@implementation A
+@end
+@implementation A (Cat)
+@end
+@protocol P
+@end
+@interface C <P>
+@end
+@implementation C
+@end