[cfe-commits] r65055 - in /cfe/trunk: include/clang/AST/Attr.h lib/Sema/SemaDeclAttr.cpp test/Sema/attr-noinline.c

Anders Carlsson andersca at mac.com
Thu Feb 19 11:16:48 PST 2009


Author: andersca
Date: Thu Feb 19 13:16:48 2009
New Revision: 65055

URL: http://llvm.org/viewvc/llvm-project?rev=65055&view=rev
Log:
Add sema support for the noinline attribute.

Added:
    cfe/trunk/test/Sema/attr-noinline.c
Modified:
    cfe/trunk/include/clang/AST/Attr.h
    cfe/trunk/lib/Sema/SemaDeclAttr.cpp

Modified: cfe/trunk/include/clang/AST/Attr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Attr.h?rev=65055&r1=65054&r2=65055&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Attr.h (original)
+++ cfe/trunk/include/clang/AST/Attr.h Thu Feb 19 13:16:48 2009
@@ -58,7 +58,8 @@
     Const,
     Pure,
     Cleanup,
-    Nodebug
+    Nodebug,
+    Noinline
   };
     
 private:
@@ -499,7 +500,7 @@
   // Implement isa/cast/dyncast/etc.
     
   static bool classof(const Attr *A) { return A->getKind() == Nodebug; }
-  static bool classof(const DeprecatedAttr *A) { return true; }
+  static bool classof(const NodebugAttr *A) { return true; }
 };
   
 class WarnUnusedResultAttr : public Attr {
@@ -510,7 +511,17 @@
   static bool classof(const Attr *A) { return A->getKind() == WarnUnusedResult;}  
   static bool classof(const WarnUnusedResultAttr *A) { return true; }
 };
-  
+
+class NoinlineAttr : public Attr {
+public:
+  NoinlineAttr() : Attr(Noinline) {}
+    
+  // Implement isa/cast/dyncast/etc.
+    
+  static bool classof(const Attr *A) { return A->getKind() == Noinline; }
+  static bool classof(const NoinlineAttr *A) { return true; }
+};
+
 }  // end namespace clang
 
 #endif

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Thu Feb 19 13:16:48 2009
@@ -395,6 +395,12 @@
     S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 0;
     return;
   }
+
+  if (!isFunctionOrMethod(d)) {
+    S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type)
+    << "always_inline" << 0 /*function*/;
+    return;
+  }
   
   d->addAttr(new AlwaysInlineAttr());
 }
@@ -1343,7 +1349,7 @@
     return;
   }
 
-  if (!isa<FunctionDecl>(d)) {
+  if (!isFunctionOrMethod(d)) {
     S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type)
       << "nodebug" << 0 /*function*/;
     return;
@@ -1352,6 +1358,22 @@
   d->addAttr(new NodebugAttr());
 }
 
+static void HandleNoinlineAttr(Decl *d, const AttributeList &Attr, Sema &S) {
+  // check the attribute arguments.
+  if (Attr.getNumArgs() != 0) {
+    S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 0;
+    return;
+  }
+  
+  if (!isFunctionOrMethod(d)) {
+    S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type)
+    << "noinline" << 0 /*function*/;
+    return;
+  }
+  
+  d->addAttr(new NoinlineAttr());
+}
+
 //===----------------------------------------------------------------------===//
 // Top Level Sema Entry Points
 //===----------------------------------------------------------------------===//
@@ -1410,6 +1432,7 @@
   case AttributeList::AT_pure:        HandlePureAttr      (D, Attr, S); break;
   case AttributeList::AT_cleanup:     HandleCleanupAttr   (D, Attr, S); break;
   case AttributeList::AT_nodebug:     HandleNodebugAttr   (D, Attr, S); break;
+  case AttributeList::AT_noinline:    HandleNoinlineAttr  (D, Attr, S); break;
   case AttributeList::IgnoredAttribute: 
     // Just ignore
     break;

Added: cfe/trunk/test/Sema/attr-noinline.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attr-noinline.c?rev=65055&view=auto

==============================================================================
--- cfe/trunk/test/Sema/attr-noinline.c (added)
+++ cfe/trunk/test/Sema/attr-noinline.c Thu Feb 19 13:16:48 2009
@@ -0,0 +1,8 @@
+// RUN: clang %s -verify -fsyntax-only
+
+int a __attribute__((noinline)); // expected-warning {{'noinline' attribute only applies to function types}}
+
+void t1() __attribute__((noinline));
+
+void t2() __attribute__((noinline(2))); // expected-error {{attribute requires 0 argument(s)}}
+





More information about the cfe-commits mailing list