[cfe-commits] r93255 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDeclAttr.cpp test/Sema/attr-section.c

Chris Lattner sabre at nondot.org
Tue Jan 12 12:58:53 PST 2010


Author: lattner
Date: Tue Jan 12 14:58:53 2010
New Revision: 93255

URL: http://llvm.org/viewvc/llvm-project?rev=93255&view=rev
Log:
implement PR6007, diagnosing invalid attribute((section))

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaDeclAttr.cpp
    cfe/trunk/test/Sema/attr-section.c

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=93255&r1=93254&r2=93255&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Jan 12 14:58:53 2010
@@ -683,6 +683,8 @@
   "argument to %0 attribute was not a string literal">;
 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 err_attribute_aligned_not_power_of_two : Error<
   "requested alignment is not a power of 2">;
 def warn_redeclaration_without_attribute_prev_attribute_ignored : Warning<

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=93255&r1=93254&r2=93255&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Tue Jan 12 14:58:53 2010
@@ -926,14 +926,19 @@
 
   // If the target wants to validate the section specifier, make it happen.
   std::string Error = S.Context.Target.isValidSectionSpecifier(SE->getString());
-  if (Error.empty()) {
-    D->addAttr(::new (S.Context) SectionAttr(SE->getString()));
+  if (!Error.empty()) {
+    S.Diag(SE->getLocStart(), diag::err_attribute_section_invalid_for_target)
+    << Error;
     return;
   }
 
-  S.Diag(SE->getLocStart(), diag::err_attribute_section_invalid_for_target)
-    << Error;
-
+  // This attribute cannot be applied to local variables.
+  if (isa<VarDecl>(D) && cast<VarDecl>(D)->hasLocalStorage()) {
+    S.Diag(SE->getLocStart(), diag::err_attribute_section_local_variable);
+    return;
+  }
+  
+  D->addAttr(::new (S.Context) SectionAttr(SE->getString()));
 }
 
 static void HandleCDeclAttr(Decl *d, const AttributeList &Attr, Sema &S) {

Modified: cfe/trunk/test/Sema/attr-section.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attr-section.c?rev=93255&r1=93254&r2=93255&view=diff

==============================================================================
--- cfe/trunk/test/Sema/attr-section.c (original)
+++ cfe/trunk/test/Sema/attr-section.c Tue Jan 12 14:58:53 2010
@@ -8,3 +8,8 @@
 int y __attribute__((section(
    "sadf"))); // expected-error {{mach-o section specifier requires a segment and section separated by a comma}}
 
+// PR6007
+void test() {
+  __attribute__((section("NEAR,x"))) int n1; // expected-error {{'section' attribute is not valid on local variables}}
+  __attribute__((section("NEAR,x"))) static int n2; // ok.
+}
\ No newline at end of file





More information about the cfe-commits mailing list