]> granicus.if.org Git - clang/commitdiff
Implemented Sema support for attribute "unused".
authorTed Kremenek <kremenek@apple.com>
Fri, 25 Jul 2008 04:39:19 +0000 (04:39 +0000)
committerTed Kremenek <kremenek@apple.com>
Fri, 25 Jul 2008 04:39:19 +0000 (04:39 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@54008 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/Attr.h
lib/Sema/SemaDeclAttr.cpp

index dd6f28f85e648dd84be0e28e299d1f14c13eba0b..0ae0acb878d69c9e74735de2349932e65fbc4650 100644 (file)
@@ -27,22 +27,22 @@ public:
   enum Kind {
     Alias,
     Aligned,
-    Packed,
     Annotate,
-    NonNull,
-    NoReturn,
     Deprecated,
-    Weak,
     DLLImport,
     DLLExport,
-    NoThrow,
+    FastCall,    
     Format,
-    Visibility,
-    FastCall,
+    IBOutletKind, // Clang-specific.  Use "Kind" suffix to not conflict with
+    NonNull,
+    NoReturn,
+    NoThrow,
+    Packed,
     StdCall,
     TransparentUnion,
-    IBOutletKind // Clang-specific.  Use "Kind" suffix to not conflict with
-                 // the IBOutlet macro.
+    Unused,    
+    Visibility,
+    Weak
   };
     
 private:
@@ -157,6 +157,15 @@ public:
   static bool classof(const DeprecatedAttr *A) { return true; }
 };
 
+class UnusedAttr : public Attr {
+public:
+  UnusedAttr() : Attr(Unused) {}
+  
+  // Implement isa/cast/dyncast/etc.
+  static bool classof(const Attr *A) { return A->getKind() == Unused; }  
+  static bool classof(const UnusedAttr *A) { return true; }
+};  
+  
 class WeakAttr : public Attr {
 public:
   WeakAttr() : Attr(Weak) {}
index 04e3f0557b762ac8439cc39020225e837c02d964..9a38f6cf351e9b3f26bff4b7ead908753b6517d6 100644 (file)
@@ -339,6 +339,25 @@ static void HandleNoReturnAttr(Decl *d, const AttributeList &Attr, Sema &S) {
   d->addAttr(new NoReturnAttr());
 }
 
+static void HandleUnusedAttr(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,
+           std::string("0"));
+    return;
+  }
+  
+  VarDecl *VD = dyn_cast<VarDecl>(d);
+  
+  if (!VD) {
+    S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type,
+           "unused", "variable");
+    return;
+  }
+  
+  d->addAttr(new UnusedAttr());
+}
+
 static void HandleDeprecatedAttr(Decl *d, const AttributeList &Attr, Sema &S) {
   // check the attribute arguments.
   if (Attr.getNumArgs() != 0) {
@@ -826,6 +845,7 @@ static void ProcessDeclAttribute(Decl *D, const AttributeList &Attr, Sema &S) {
   case AttributeList::AT_format:      HandleFormatAttr    (D, Attr, S); break;
   case AttributeList::AT_IBOutlet:    HandleIBOutletAttr  (D, Attr, S); break;
   case AttributeList::AT_nonnull:     HandleNonNullAttr   (D, Attr, S); break;
+  case AttributeList::AT_unused:      HandleUnusedAttr    (D, Attr, S); break;
   case AttributeList::AT_transparent_union:
     HandleTransparentUnionAttr(D, Attr, S);
     break;