]> granicus.if.org Git - clang/commitdiff
ObjectiveC. support "section" attribute on properties
authorFariborz Jahanian <fjahanian@apple.com>
Wed, 18 Dec 2013 23:09:57 +0000 (23:09 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Wed, 18 Dec 2013 23:09:57 +0000 (23:09 +0000)
and methods. rdar://15450637

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@197625 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/Attr.td
include/clang/Sema/AttributeList.h
lib/Sema/SemaObjCProperty.cpp
test/CodeGenObjC/property-section-attribute.m [new file with mode: 0644]

index 38cf10bee3d69130590dc4dcfc3eea4ff515db4e..f8e4eeb22240f68d615c86ac345c009ff39f5e20 100644 (file)
@@ -818,8 +818,9 @@ def InitPriority : InheritableAttr {
 def Section : InheritableAttr {
   let Spellings = [GNU<"section">, CXX11<"gnu", "section">];
   let Args = [StringArgument<"Name">];
-  let Subjects = SubjectList<[Function, GlobalVar], ErrorDiag,
-                             "ExpectedFunctionOrGlobalVar">;
+  let Subjects = SubjectList<[Function, GlobalVar, 
+                              ObjCMethod, ObjCProperty], ErrorDiag,
+                             "ExpectedFunctionGlobalVarMethodOrProperty">;
 }
 
 def Sentinel : InheritableAttr {
index f31435546ae5710ce86b5af8200d8dbaab6f1269..8d9fee4195d733773912547f852d61902061c4ec 100644 (file)
@@ -912,7 +912,7 @@ enum AttributeDeclKind {
   ExpectedObjCInterfaceDeclInitMethod,
   ExpectedFunctionVariableOrClass,
   ExpectedObjectiveCProtocol,
-  ExpectedFunctionOrGlobalVar
+  ExpectedFunctionGlobalVarMethodOrProperty
 };
 
 }  // end namespace clang
index 93791d7667ce0b400470cb135495ec8c64e4a30c..61e58c4bef76fb93d1e5a91638a8d171226e6210 100644 (file)
@@ -1934,6 +1934,10 @@ void Sema::ProcessPropertyDecl(ObjCPropertyDecl *property,
     if (property->hasAttr<ObjCReturnsInnerPointerAttr>())
       GetterMethod->addAttr(
         ::new (Context) ObjCReturnsInnerPointerAttr(Loc, Context));
+    
+    if (const SectionAttr *SA = property->getAttr<SectionAttr>())
+      GetterMethod->addAttr(::new (Context) SectionAttr(Loc,
+                                                        Context, SA->getName()));
 
     if (getLangOpts().ObjCAutoRefCount)
       CheckARCMethodDecl(GetterMethod);
@@ -1984,7 +1988,9 @@ void Sema::ProcessPropertyDecl(ObjCPropertyDecl *property,
       // and the real context should be the same.
       if (lexicalDC)
         SetterMethod->setLexicalDeclContext(lexicalDC);
-
+      if (const SectionAttr *SA = property->getAttr<SectionAttr>())
+        SetterMethod->addAttr(::new (Context) SectionAttr(Loc,
+                                                          Context, SA->getName()));
       // It's possible for the user to have set a very odd custom
       // setter selector that causes it to have a method family.
       if (getLangOpts().ObjCAutoRefCount)
diff --git a/test/CodeGenObjC/property-section-attribute.m b/test/CodeGenObjC/property-section-attribute.m
new file mode 100644 (file)
index 0000000..5ba064c
--- /dev/null
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -o - %s | FileCheck %s
+// rdar://15450637.
+
+@interface NSObject @end
+
+@interface Foo : NSObject
+@property int p __attribute__((section("__TEXT,foo")));
+@end
+
+@implementation Foo @end
+
+// CHECK: define internal i32 @"\01-[Foo p]"({{.*}} section "__TEXT,foo" {
+// CHECK: define internal void @"\01-[Foo setP:]"({{.*}} section "__TEXT,foo" {