[cfe-commits] r54008 - in /cfe/trunk: include/clang/AST/Attr.h lib/Sema/SemaDeclAttr.cpp
Ted Kremenek
kremenek at apple.com
Thu Jul 24 21:39:19 PDT 2008
Author: kremenek
Date: Thu Jul 24 23:39:19 2008
New Revision: 54008
URL: http://llvm.org/viewvc/llvm-project?rev=54008&view=rev
Log:
Implemented Sema support for attribute "unused".
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=54008&r1=54007&r2=54008&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Attr.h (original)
+++ cfe/trunk/include/clang/AST/Attr.h Thu Jul 24 23:39:19 2008
@@ -27,22 +27,22 @@
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 @@
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) {}
Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=54008&r1=54007&r2=54008&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Thu Jul 24 23:39:19 2008
@@ -339,6 +339,25 @@
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 @@
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;
More information about the cfe-commits
mailing list