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

Chris Lattner sabre at nondot.org
Tue Apr 14 10:02:12 PDT 2009


Author: lattner
Date: Tue Apr 14 12:02:11 2009
New Revision: 69051

URL: http://llvm.org/viewvc/llvm-project?rev=69051&view=rev
Log:
implement some sema for gnuc_inline attribute.  Reject always_inline and no_inline on objc methods.

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

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

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Apr 14 12:02:11 2009
@@ -398,6 +398,11 @@
 def warn_attribute_wrong_decl_type : Warning<
   "'%0' attribute only applies to %select{function|union|"
   "variable and function|function or method}1 types">;
+def warn_gnuc_inline_attribute_requires_inline : Warning<
+  "'gnuc_inline' attribute requires function to be marked 'inline',"
+  " attribute ignored">;
+def warn_gnuc_inline_attribute_extern_inline : Warning<
+ "'gnuc_inline' attribute is overridden by 'extern inline', attribute ignored">;
 
 def warn_attribute_ignored_for_field_of_type : Warning<
   "%0 attribute ignored for field of type %1">;

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Tue Apr 14 12:02:11 2009
@@ -391,7 +391,7 @@
     return;
   }
 
-  if (!isFunctionOrMethod(d)) {
+  if (!isa<FunctionDecl>(d)) {
     S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type)
     << "always_inline" << 0 /*function*/;
     return;
@@ -485,8 +485,7 @@
     priority = Idx.getZExtValue();
   }
   
-  FunctionDecl *Fn = dyn_cast<FunctionDecl>(d);
-  if (!Fn) {
+  if (!isa<FunctionDecl>(d)) {
     S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type)
       << "constructor" << 0 /*function*/;
     return;
@@ -1447,7 +1446,7 @@
     return;
   }
   
-  if (!isFunctionOrMethod(d)) {
+  if (!isa<FunctionDecl>(d)) {
     S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type)
     << "noinline" << 0 /*function*/;
     return;
@@ -1463,12 +1462,23 @@
     return;
   }
   
-  if (!isFunctionOrMethod(d)) {
+  FunctionDecl *Fn = dyn_cast<FunctionDecl>(d);
+  if (Fn == 0) {
     S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type)
       << "gnuc_inline" << 0 /*function*/;
     return;
   }
   
+  if (!Fn->isInline()) {
+    S.Diag(Attr.getLoc(), diag::warn_gnuc_inline_attribute_requires_inline);
+    return;
+  }
+  
+  if (Fn->getStorageClass() == FunctionDecl::Extern) {
+    S.Diag(Attr.getLoc(), diag::warn_gnuc_inline_attribute_extern_inline);
+    return;
+  }
+  
   d->addAttr(::new (S.Context) GNUCInlineAttr());
 }
 

Modified: cfe/trunk/test/Sema/function.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/function.c?rev=69051&r1=69050&r2=69051&view=diff

==============================================================================
--- cfe/trunk/test/Sema/function.c (original)
+++ cfe/trunk/test/Sema/function.c Tue Apr 14 12:02:11 2009
@@ -61,3 +61,12 @@
 
 struct incomplete_test a(void) {} // expected-error{{incomplete result type 'struct incomplete_test' in function definition}} \
     // expected-note{{forward declaration of 'struct incomplete_test'}}
+
+
+extern __inline
+__attribute__((__gnuc_inline__))  // expected-warning{{'gnuc_inline' attribute is overridden by 'extern inline', attribute ignored}} expected-warning{{extension used}}
+void gnu_inline1() {}
+
+void
+__attribute__((__gnuc_inline__)) // expected-warning {{'gnuc_inline' attribute requires function to be marked 'inline', attribute ignored}} expected-warning{{extension used}}
+gnu_inline2() {}





More information about the cfe-commits mailing list