forked from OSchip/llvm-project
Implemented Sema support for attribute "unused".
llvm-svn: 54008
This commit is contained in:
parent
7334350d31
commit
39c59a8887
|
@ -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) {}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue