diff options
author | Ted Kremenek <kremenek@apple.com> | 2009-08-03 23:24:57 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2009-08-03 23:24:57 +0000 |
commit | 7a02a3733cdd2ca672902d869fda4ef2e3f05052 (patch) | |
tree | 818f89d2f2c93249173392518c282bf95e36d034 /lib/Parse/ParsePragma.cpp | |
parent | 48775d5bf05120adb2a953bbcd626405bf666b22 (diff) |
Per advice that Doug Gregor gave me several months ago, clean up the
implementation of '#pragma unused' by not constructing intermediate
DeclRefExprs, but instead do the name lookup directly. The
implementation is greatly simplified.
Along the way, degrade '#pragma unused(undeclaredvariable)' to a
warning instead of being a hard error. This implements:
<rdar://problem/6761874> [sema] allow #pragma unused to reference undefined variable (with warning)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@78019 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Parse/ParsePragma.cpp')
-rw-r--r-- | lib/Parse/ParsePragma.cpp | 33 |
1 files changed, 8 insertions, 25 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 |