Index: include/clang/Basic/Attr.td
===================================================================
--- include/clang/Basic/Attr.td	(revision 196138)
+++ include/clang/Basic/Attr.td	(working copy)
@@ -49,6 +49,9 @@
 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;
@@ -765,6 +768,8 @@
 def Section : InheritableAttr {
   let Spellings = [GNU<"section">, CXX11<"gnu", "section">];
   let Args = [StringArgument<"Name">];
+  let Subjects = SubjectList<[Function, GlobalVar], ErrorDiag,
+                             "ExpectedFunctionOrGlobalVar">;
 }
 
 def Sentinel : InheritableAttr {
Index: include/clang/Basic/DiagnosticSemaKinds.td
===================================================================
--- include/clang/Basic/DiagnosticSemaKinds.td	(revision 196120)
+++ include/clang/Basic/DiagnosticSemaKinds.td	(working copy)
@@ -1941,8 +1941,6 @@
 
 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>;
 
@@ -2037,7 +2035,8 @@
   "variables and fields|variables, data members and tag types|"
   "types and namespaces|Objective-C interfaces|methods and properties|"
   "struct or union|struct, union or class|types|"
-  "Objective-C instance methods|variables, functions and classes}1">,
+  "Objective-C instance methods|variables, functions and classes|"
+  "functions and global variables}1">,
   InGroup<IgnoredAttributes>;
 def err_attribute_wrong_decl_type : Error<
   "%0 attribute only applies to %select{functions|unions|"
@@ -2049,7 +2048,8 @@
   "variables and fields|variables, data members and tag types|"
   "types and namespaces|Objective-C interfaces|methods and properties|"
   "struct or union|struct, union or class|types|"
-  "Objective-C instance methods|variables, functions and classes}1">;
+  "Objective-C instance methods|variables, functions and classes|"
+  "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">,
Index: include/clang/Sema/AttributeList.h
===================================================================
--- include/clang/Sema/AttributeList.h	(revision 196138)
+++ include/clang/Sema/AttributeList.h	(working copy)
@@ -861,7 +861,8 @@
   ExpectedStructOrUnionOrClass,
   ExpectedType,
   ExpectedObjCInstanceMethod,
-  ExpectedFunctionVariableOrClass
+  ExpectedFunctionVariableOrClass,
+  ExpectedFunctionOrGlobalVar
 };
 
 }  // end namespace clang
Index: lib/Sema/SemaDeclAttr.cpp
===================================================================
--- lib/Sema/SemaDeclAttr.cpp	(revision 196155)
+++ lib/Sema/SemaDeclAttr.cpp	(working copy)
@@ -2382,12 +2382,6 @@
     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)
Index: test/Sema/attr-section.c
===================================================================
--- test/Sema/attr-section.c	(revision 196100)
+++ test/Sema/attr-section.c	(working copy)
@@ -10,7 +10,7 @@
 
 // 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.
 }
 
@@ -17,3 +17,5 @@
 // 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}}
