diff options
author | Anders Carlsson <andersca@mac.com> | 2010-10-22 23:37:08 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2010-10-22 23:37:08 +0000 |
commit | 2127eccbe15fd3b1b29aa53ccedd2e0f55ad27f9 (patch) | |
tree | f3308f8ee6379e9247351a366149282457eb9ccb /lib/Sema | |
parent | 5b629aa86c987f276d00453b6c9ab8424f7903fe (diff) |
Warn if a variable marked with the "unused" attribute is used. Patch by Darin Adler!
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@117184 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema')
-rw-r--r-- | lib/Sema/SemaAttr.cpp | 4 | ||||
-rw-r--r-- | lib/Sema/SemaExpr.cpp | 6 |
2 files changed, 9 insertions, 1 deletions
diff --git a/lib/Sema/SemaAttr.cpp b/lib/Sema/SemaAttr.cpp index 0921156b93..d7290c3089 100644 --- a/lib/Sema/SemaAttr.cpp +++ b/lib/Sema/SemaAttr.cpp @@ -288,6 +288,10 @@ void Sema::ActOnPragmaUnused(const Token *Identifiers, unsigned NumIdentifiers, continue; } + // Warn if this was used before being marked unused. + if (VD->isUsed()) + Diag(PragmaLoc, diag::warn_used_but_marked_unused) << Name; + VD->addAttr(::new (Context) UnusedAttr(Tok.getLocation(), Context)); } } diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 587a76ed08..ced383310f 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -97,6 +97,10 @@ bool Sema::DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc) { } } + // Warn if this is used but marked unused. + if (D->hasAttr<UnusedAttr>()) + Diag(Loc, diag::warn_used_but_marked_unused) << D->getDeclName(); + return false; } @@ -7804,7 +7808,7 @@ void Sema::MarkDeclarationReferenced(SourceLocation Loc, Decl *D) { // -Wunused-parameters) if (isa<ParmVarDecl>(D) || (isa<VarDecl>(D) && D->getDeclContext()->isFunctionOrMethod())) { - D->setUsed(true); + D->setUsed(); return; } |