From: Fariborz Jahanian Date: Wed, 18 Dec 2013 23:09:57 +0000 (+0000) Subject: ObjectiveC. support "section" attribute on properties X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1ba0a8ed202412605157d6af05c41859fdef699c;p=clang ObjectiveC. support "section" attribute on properties and methods. rdar://15450637 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@197625 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/Attr.td b/include/clang/Basic/Attr.td index 38cf10bee3..f8e4eeb222 100644 --- a/include/clang/Basic/Attr.td +++ b/include/clang/Basic/Attr.td @@ -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 { diff --git a/include/clang/Sema/AttributeList.h b/include/clang/Sema/AttributeList.h index f31435546a..8d9fee4195 100644 --- a/include/clang/Sema/AttributeList.h +++ b/include/clang/Sema/AttributeList.h @@ -912,7 +912,7 @@ enum AttributeDeclKind { ExpectedObjCInterfaceDeclInitMethod, ExpectedFunctionVariableOrClass, ExpectedObjectiveCProtocol, - ExpectedFunctionOrGlobalVar + ExpectedFunctionGlobalVarMethodOrProperty }; } // end namespace clang diff --git a/lib/Sema/SemaObjCProperty.cpp b/lib/Sema/SemaObjCProperty.cpp index 93791d7667..61e58c4bef 100644 --- a/lib/Sema/SemaObjCProperty.cpp +++ b/lib/Sema/SemaObjCProperty.cpp @@ -1934,6 +1934,10 @@ void Sema::ProcessPropertyDecl(ObjCPropertyDecl *property, if (property->hasAttr()) GetterMethod->addAttr( ::new (Context) ObjCReturnsInnerPointerAttr(Loc, Context)); + + if (const SectionAttr *SA = property->getAttr()) + 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()) + 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 index 0000000000..5ba064c612 --- /dev/null +++ b/test/CodeGenObjC/property-section-attribute.m @@ -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" {