r197104 - Added a Subjects clause to the section attribute and made its diagnostics more consistent with other attributes.
Aaron Ballman
aaron at aaronballman.com
Wed Dec 11 17:34:39 PST 2013
Author: aaronballman
Date: Wed Dec 11 19:34:39 2013
New Revision: 197104
URL: http://llvm.org/viewvc/llvm-project?rev=197104&view=rev
Log:
Added a Subjects clause to the section attribute and made its diagnostics more consistent with other attributes.
Modified:
cfe/trunk/include/clang/Basic/Attr.td
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Sema/AttributeList.h
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/test/Sema/attr-section.c
Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=197104&r1=197103&r2=197104&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Wed Dec 11 19:34:39 2013
@@ -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 {
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=197104&r1=197103&r2=197104&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Dec 11 19:34:39 2013
@@ -1941,8 +1941,6 @@ def err_only_annotate_after_access_spec
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 : War
"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 : Erro
"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">,
Modified: cfe/trunk/include/clang/Sema/AttributeList.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/AttributeList.h?rev=197104&r1=197103&r2=197104&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/AttributeList.h (original)
+++ cfe/trunk/include/clang/Sema/AttributeList.h Wed Dec 11 19:34:39 2013
@@ -911,7 +911,8 @@ enum AttributeDeclKind {
ExpectedObjCInstanceMethod,
ExpectedObjCInterfaceDeclInitMethod,
ExpectedFunctionVariableOrClass,
- ExpectedObjectiveCProtocol
+ ExpectedObjectiveCProtocol,
+ ExpectedFunctionOrGlobalVar
};
} // end namespace clang
Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=197104&r1=197103&r2=197104&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Wed Dec 11 19:34:39 2013
@@ -2349,12 +2349,6 @@ static void handleSectionAttr(Sema &S, D
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)
Modified: cfe/trunk/test/Sema/attr-section.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attr-section.c?rev=197104&r1=197103&r2=197104&view=diff
==============================================================================
--- cfe/trunk/test/Sema/attr-section.c (original)
+++ cfe/trunk/test/Sema/attr-section.c Wed Dec 11 19:34:39 2013
@@ -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}}
More information about the cfe-commits
mailing list