forked from OSchip/llvm-project
Added a Subjects clause to the section attribute and made its diagnostics more consistent with other attributes.
llvm-svn: 197104
This commit is contained in:
parent
c934e4fd2c
commit
75a1729c4b
|
@ -53,6 +53,9 @@ def TLSVar : SubsetSubject<Var,
|
|||
def SharedVar : SubsetSubject<Var,
|
||||
[{S->hasGlobalStorage() && !S->getTLSKind()}]>;
|
||||
|
||||
def GlobalVar : SubsetSubject<Var,
|
||||
[{!S->hasLocalStorage()}]>;
|
||||
|
||||
// A single argument to an attribute
|
||||
class Argument<string name, bit optional> {
|
||||
string Name = name;
|
||||
|
@ -787,6 +790,8 @@ def InitPriority : InheritableAttr {
|
|||
def Section : InheritableAttr {
|
||||
let Spellings = [GNU<"section">, CXX11<"gnu", "section">];
|
||||
let Args = [StringArgument<"Name">];
|
||||
let Subjects = SubjectList<[Function, GlobalVar], ErrorDiag,
|
||||
"ExpectedFunctionOrGlobalVar">;
|
||||
}
|
||||
|
||||
def Sentinel : InheritableAttr {
|
||||
|
|
|
@ -1941,8 +1941,6 @@ def err_only_annotate_after_access_spec : Error<
|
|||
|
||||
def err_attribute_section_invalid_for_target : Error<
|
||||
"argument to 'section' attribute is not valid for this target: %0">;
|
||||
def err_attribute_section_local_variable : Error<
|
||||
"'section' attribute is not valid on local variables">;
|
||||
def warn_mismatched_section : Warning<
|
||||
"section does not match previous declaration">, InGroup<Section>;
|
||||
|
||||
|
@ -2038,7 +2036,8 @@ def warn_attribute_wrong_decl_type : Warning<
|
|||
"types and namespaces|Objective-C interfaces|methods and properties|"
|
||||
"struct or union|struct, union or class|types|"
|
||||
"Objective-C instance methods|init methods of interface declarations|"
|
||||
"variables, functions and classes|Objective-C protocols}1">,
|
||||
"variables, functions and classes|Objective-C protocols|"
|
||||
"functions and global variables}1">,
|
||||
InGroup<IgnoredAttributes>;
|
||||
def err_attribute_wrong_decl_type : Error<
|
||||
"%0 attribute only applies to %select{functions|unions|"
|
||||
|
@ -2051,7 +2050,8 @@ def err_attribute_wrong_decl_type : Error<
|
|||
"types and namespaces|Objective-C interfaces|methods and properties|"
|
||||
"struct or union|struct, union or class|types|"
|
||||
"Objective-C instance methods|init methods of interface declarations|"
|
||||
"variables, functions and classes|Objective-C protocols}1">;
|
||||
"variables, functions and classes|Objective-C protocols|"
|
||||
"functions and global variables}1">;
|
||||
def warn_type_attribute_wrong_type : Warning<
|
||||
"'%0' only applies to %select{function|pointer|"
|
||||
"Objective-C object or block pointer}1 types; type here is %2">,
|
||||
|
|
|
@ -911,7 +911,8 @@ enum AttributeDeclKind {
|
|||
ExpectedObjCInstanceMethod,
|
||||
ExpectedObjCInterfaceDeclInitMethod,
|
||||
ExpectedFunctionVariableOrClass,
|
||||
ExpectedObjectiveCProtocol
|
||||
ExpectedObjectiveCProtocol,
|
||||
ExpectedFunctionOrGlobalVar
|
||||
};
|
||||
|
||||
} // end namespace clang
|
||||
|
|
|
@ -2349,12 +2349,6 @@ static void handleSectionAttr(Sema &S, Decl *D, const AttributeList &Attr) {
|
|||
return;
|
||||
}
|
||||
|
||||
// This attribute cannot be applied to local variables.
|
||||
if (isa<VarDecl>(D) && cast<VarDecl>(D)->hasLocalStorage()) {
|
||||
S.Diag(LiteralLoc, diag::err_attribute_section_local_variable);
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned Index = Attr.getAttributeSpellingListIndex();
|
||||
SectionAttr *NewAttr = S.mergeSectionAttr(D, Attr.getRange(), Str, Index);
|
||||
if (NewAttr)
|
||||
|
|
|
@ -10,10 +10,12 @@ int y __attribute__((section(
|
|||
|
||||
// PR6007
|
||||
void test() {
|
||||
__attribute__((section("NEAR,x"))) int n1; // expected-error {{'section' attribute is not valid on local variables}}
|
||||
__attribute__((section("NEAR,x"))) int n1; // expected-error {{'section' attribute only applies to functions and global variables}}
|
||||
__attribute__((section("NEAR,x"))) static int n2; // ok.
|
||||
}
|
||||
|
||||
// pr9356
|
||||
void __attribute__((section("foo,zed"))) test2(void); // expected-note {{previous attribute is here}}
|
||||
void __attribute__((section("bar,zed"))) test2(void) {} // expected-warning {{section does not match previous declaration}}
|
||||
|
||||
enum __attribute__((section("NEAR,x"))) e { one }; // expected-error {{'section' attribute only applies to functions and global variables}}
|
||||
|
|
Loading…
Reference in New Issue