"specifying both a name and alignment to 'pop' is undefined">;
def warn_pragma_pack_pop_failed : Warning<"#pragma pack(pop, ...) failed: %0">;
+def warn_pragma_unused_undeclared_var : Warning<
+ "undeclared variable %0 used as an argument for '#pragma unused'">;
def warn_pragma_unused_expected_localvar : Warning<
"only local variables can be arguments to '#pragma unused'">;
def err_unsupported_pragma_weak : Error<
}
/// ActOnPragmaUnused - Called on well formed #pragma unused(...).
- virtual void ActOnPragmaUnused(ExprTy **Exprs, unsigned NumExprs,
+ virtual void ActOnPragmaUnused(const Token *Identifiers,
+ unsigned NumIdentifiers, Scope *CurScope,
SourceLocation PragmaLoc,
SourceLocation LParenLoc,
SourceLocation RParenLoc) {
SourceLocation LParenLoc = Tok.getLocation();
// Lex the declaration reference(s).
- llvm::SmallVector<Action::ExprTy*, 5> Ex;
+ llvm::SmallVector<Token, 5> Identifiers;
SourceLocation RParenLoc;
bool LexID = true;
PP.Lex(Tok);
if (LexID) {
- if (Tok.is(tok::identifier)) {
- Action::OwningExprResult Name =
- Actions.ActOnIdentifierExpr(parser.CurScope, Tok.getLocation(),
- *Tok.getIdentifierInfo(), false);
-
- if (Name.isInvalid()) {
- if (!Ex.empty())
- Action::MultiExprArg Release(Actions, &Ex[0], Ex.size());
- return;
- }
-
- Ex.push_back(Name.release());
+ if (Tok.is(tok::identifier)) {
+ Identifiers.push_back(Tok);
LexID = false;
continue;
}
- // Illegal token! Release the parsed expressions (if any) and emit
- // a warning.
- if (!Ex.empty())
- Action::MultiExprArg Release(Actions, &Ex[0], Ex.size());
-
+ // Illegal token!
PP.Diag(Tok.getLocation(), diag::warn_pragma_unused_expected_var);
return;
}
break;
}
- // Illegal token! Release the parsed expressions (if any) and emit
- // a warning.
- if (!Ex.empty())
- Action::MultiExprArg Release(Actions, &Ex[0], Ex.size());
-
+ // Illegal token!
PP.Diag(Tok.getLocation(), diag::warn_pragma_unused_expected_punc);
return;
}
// Verify that we have a location for the right parenthesis.
assert(RParenLoc.isValid() && "Valid '#pragma unused' must have ')'");
- assert(!Ex.empty() && "Valid '#pragma unused' must have arguments");
+ assert(!Identifiers.empty() && "Valid '#pragma unused' must have arguments");
// Perform the action to handle the pragma.
- Actions.ActOnPragmaUnused(&Ex[0], Ex.size(), UnusedLoc, LParenLoc, RParenLoc);
+ Actions.ActOnPragmaUnused(Identifiers.data(), Identifiers.size(),
+ parser.CurScope, UnusedLoc, LParenLoc, RParenLoc);
}
// #pragma weak identifier
SourceLocation RParenLoc);
/// ActOnPragmaUnused - Called on well-formed '#pragma unused'.
- virtual void ActOnPragmaUnused(ExprTy **Exprs, unsigned NumExprs,
+ virtual void ActOnPragmaUnused(const Token *Identifiers,
+ unsigned NumIdentifiers, Scope *curScope,
SourceLocation PragmaLoc,
SourceLocation LParenLoc,
SourceLocation RParenLoc);
}
}
-void Sema::ActOnPragmaUnused(ExprTy **Exprs, unsigned NumExprs,
+void Sema::ActOnPragmaUnused(const Token *Identifiers, unsigned NumIdentifiers,
+ Scope *curScope,
SourceLocation PragmaLoc,
SourceLocation LParenLoc,
SourceLocation RParenLoc) {
-
- // Verify that all of the expressions are valid before
- // modifying the attributes of any referenced decl.
- Expr *ErrorExpr = 0;
-
- for (unsigned i = 0; i < NumExprs; ++i) {
- Expr *Ex = (Expr*) Exprs[i];
- if (!isa<DeclRefExpr>(Ex)) {
- ErrorExpr = Ex;
- break;
- }
- Decl *d = cast<DeclRefExpr>(Ex)->getDecl();;
-
- if (!isa<VarDecl>(d) || !cast<VarDecl>(d)->hasLocalStorage()) {
- ErrorExpr = Ex;
- break;
+ for (unsigned i = 0; i < NumIdentifiers; ++i) {
+ const Token &Tok = Identifiers[i];
+ IdentifierInfo *Name = Tok.getIdentifierInfo();
+ const LookupResult &Lookup = LookupParsedName(curScope, NULL, Name,
+ LookupOrdinaryName,
+ false, true,
+ Tok.getLocation());
+ // FIXME: Handle Lookup.isAmbiguous?
+
+ NamedDecl *ND = Lookup.getAsDecl();
+
+ if (!ND) {
+ Diag(PragmaLoc, diag::warn_pragma_unused_undeclared_var)
+ << Name << SourceRange(Tok.getLocation());
+ continue;
}
- }
-
- // Delete the expressions if we encountered any error.
- if (ErrorExpr) {
- Diag(ErrorExpr->getLocStart(), diag::warn_pragma_unused_expected_localvar);
- for (unsigned i = 0; i < NumExprs; ++i)
- ((Expr*) Exprs[i])->Destroy(Context);
- return;
- }
- // Otherwise, add the 'unused' attribute to each referenced declaration.
- for (unsigned i = 0; i < NumExprs; ++i) {
- DeclRefExpr *DR = (DeclRefExpr*) Exprs[i];
- DR->getDecl()->addAttr(::new (Context) UnusedAttr());
- DR->Destroy(Context);
+ if (!isa<VarDecl>(ND) || !cast<VarDecl>(ND)->hasLocalStorage()) {
+ Diag(PragmaLoc, diag::warn_pragma_unused_expected_localvar)
+ << Name << SourceRange(Tok.getLocation());
+ continue;
+ }
+
+ ND->addAttr(::new (Context) UnusedAttr());
}
}
}
void f3(void) {
- #pragma unused(x) // expected-error{{use of undeclared identifier 'x'}}
+ #pragma unused(x) // expected-warning{{undeclared variable 'x' used as an argument for '#pragma unused'}}
}
void f4(void) {
int k;
void f5(void) {
- #pragma unused(k) // expected-warning{{only local variables can be arguments to '#pragma unused' - ignored}}
+ #pragma unused(k) // expected-warning{{only local variables can be arguments to '#pragma unused'}}
}
void f6(void) {
}
}
+void f7() {
+ int y;
+ #pragma unused(undeclared, undefined, y) // expected-warning{{undeclared variable 'undeclared' used as an argument for '#pragma unused'}} expected-warning{{undeclared variable 'undefined' used as an argument for '#pragma unused'}}
+}
+