[cfe-commits] r64441 - in /cfe/trunk: include/clang/AST/Attr.h include/clang/Parse/AttributeList.h lib/Parse/AttributeList.cpp lib/Sema/SemaDeclAttr.cpp test/Sema/attr-nodebug.c

Anders Carlsson andersca at mac.com
Thu Feb 12 22:46:15 PST 2009


Author: andersca
Date: Fri Feb 13 00:46:13 2009
New Revision: 64441

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

Added:
    cfe/trunk/test/Sema/attr-nodebug.c
Modified:
    cfe/trunk/include/clang/AST/Attr.h
    cfe/trunk/include/clang/Parse/AttributeList.h
    cfe/trunk/lib/Parse/AttributeList.cpp
    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=64441&r1=64440&r2=64441&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Attr.h (original)
+++ cfe/trunk/include/clang/AST/Attr.h Fri Feb 13 00:46:13 2009
@@ -55,7 +55,8 @@
     Blocks,
     Const,
     Pure,
-    Cleanup
+    Cleanup,
+    Nodebug
   };
     
 private:
@@ -493,6 +494,16 @@
   static bool classof(const CleanupAttr *A) { return true; }
 };
 
+class NodebugAttr : public Attr {
+public:
+  NodebugAttr() : Attr(Nodebug) {}
+    
+  // Implement isa/cast/dyncast/etc.
+    
+  static bool classof(const Attr *A) { return A->getKind() == Nodebug; }
+  static bool classof(const DeprecatedAttr *A) { return true; }
+};
+  
 }  // end namespace clang
 
 #endif

Modified: cfe/trunk/include/clang/Parse/AttributeList.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/AttributeList.h?rev=64441&r1=64440&r2=64441&view=diff

==============================================================================
--- cfe/trunk/include/clang/Parse/AttributeList.h (original)
+++ cfe/trunk/include/clang/Parse/AttributeList.h Fri Feb 13 00:46:13 2009
@@ -80,6 +80,7 @@
     AT_const,
     AT_nsobject,
     AT_cleanup,
+    AT_nodebug,
     UnknownAttribute
   };
   

Modified: cfe/trunk/lib/Parse/AttributeList.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/AttributeList.cpp?rev=64441&r1=64440&r2=64441&view=diff

==============================================================================
--- cfe/trunk/lib/Parse/AttributeList.cpp (original)
+++ cfe/trunk/lib/Parse/AttributeList.cpp Fri Feb 13 00:46:13 2009
@@ -70,6 +70,7 @@
   case 7:
     if (!memcmp(Str, "aligned", 7)) return AT_aligned;
     if (!memcmp(Str, "cleanup", 7)) return AT_cleanup;
+    if (!memcmp(Str, "nodebug", 7)) return AT_nodebug;
     if (!memcmp(Str, "nonnull", 7)) return AT_nonnull;
     if (!memcmp(Str, "nothrow", 7)) return AT_nothrow;
     if (!memcmp(Str, "objc_gc", 7)) return AT_objc_gc;

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Fri Feb 13 00:46:13 2009
@@ -1304,6 +1304,22 @@
     cast<ValueDecl>(D)->setType(NewTy);
 }
 
+static void HandleNodebugAttr(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;
+  }
+  FunctionDecl *Fn = dyn_cast<FunctionDecl>(d);
+  if (!Fn) {
+    S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type)
+      << "nodebug" << "function";
+    return;
+  }
+  
+  d->addAttr(new NodebugAttr());
+}
+
 //===----------------------------------------------------------------------===//
 // Top Level Sema Entry Points
 //===----------------------------------------------------------------------===//
@@ -1355,10 +1371,11 @@
   case AttributeList::AT_const:       HandleConstAttr     (D, Attr, S); break;
   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;
   default:
 #if 0
     // TODO: when we have the full set of attributes, warn about unknown ones.
-    S.Diag(Attr->getLoc(), diag::warn_attribute_ignored) << Attr->getName();
+    S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << Attr.getName();
 #endif
     break;
   }

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

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





More information about the cfe-commits mailing list