diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Parse/ParsePragma.cpp | 33 | ||||
-rw-r--r-- | lib/Sema/Sema.h | 3 | ||||
-rw-r--r-- | lib/Sema/SemaAttr.cpp | 55 |
3 files changed, 34 insertions, 57 deletions
diff --git a/lib/Parse/ParsePragma.cpp b/lib/Parse/ParsePragma.cpp index 58c729aef2..68b10934b1 100644 --- a/lib/Parse/ParsePragma.cpp +++ b/lib/Parse/ParsePragma.cpp @@ -126,7 +126,7 @@ void PragmaUnusedHandler::HandlePragma(Preprocessor &PP, Token &UnusedTok) { 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; @@ -134,27 +134,13 @@ void PragmaUnusedHandler::HandlePragma(Preprocessor &PP, Token &UnusedTok) { 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; } @@ -170,11 +156,7 @@ void PragmaUnusedHandler::HandlePragma(Preprocessor &PP, Token &UnusedTok) { 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; } @@ -188,10 +170,11 @@ void PragmaUnusedHandler::HandlePragma(Preprocessor &PP, Token &UnusedTok) { // 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 diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h index 0dbb9f81d1..2a77f21a2d 100644 --- a/lib/Sema/Sema.h +++ b/lib/Sema/Sema.h @@ -2953,7 +2953,8 @@ public: 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); diff --git a/lib/Sema/SemaAttr.cpp b/lib/Sema/SemaAttr.cpp index 1bf8444c42..6622d53659 100644 --- a/lib/Sema/SemaAttr.cpp +++ b/lib/Sema/SemaAttr.cpp @@ -170,42 +170,35 @@ void Sema::ActOnPragmaPack(PragmaPackKind Kind, IdentifierInfo *Name, } } -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()); } } |