diff options
author | David Blaikie <dblaikie@gmail.com> | 2016-02-09 18:52:09 +0000 |
---|---|---|
committer | David Blaikie <dblaikie@gmail.com> | 2016-02-09 18:52:09 +0000 |
commit | 2eabcc988f636cd98e9bb2c5c5e3ad5913e7267c (patch) | |
tree | 5155a49f343e8e5b3726ffadc53f2165d4acf64c /clang/lib/Lex | |
parent | cb1175c7db87175ce4231555ad9eb75b762bb0d1 (diff) | |
download | bcm5719-llvm-2eabcc988f636cd98e9bb2c5c5e3ad5913e7267c.tar.gz bcm5719-llvm-2eabcc988f636cd98e9bb2c5c5e3ad5913e7267c.zip |
Simplify EnterTokenStream API to make it more robust for memory management
While this won't help fix things like the bug that r260219 addressed, it
seems like good tidy up to have anyway.
(it might be nice if "makeArrayRef" always produced a MutableArrayRef &
let it decay to an ArrayRef when needed - then I'd use that for the
MutableArrayRefs in this patch)
If we had std::dynarray I'd use that instead of unique_ptr+size_t,
ideally (but then it'd have to be threaded down through the Preprocessor
all the way - no idea how painful that would be)
llvm-svn: 260246
Diffstat (limited to 'clang/lib/Lex')
-rw-r--r-- | clang/lib/Lex/PPDirectives.cpp | 8 | ||||
-rw-r--r-- | clang/lib/Lex/PPMacroExpansion.cpp | 11 | ||||
-rw-r--r-- | clang/lib/Lex/Pragma.cpp | 12 |
3 files changed, 15 insertions, 16 deletions
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp index c02a0cb8d30..1c74a1702a7 100644 --- a/clang/lib/Lex/PPDirectives.cpp +++ b/clang/lib/Lex/PPDirectives.cpp @@ -907,7 +907,7 @@ void Preprocessor::HandleDirective(Token &Result) { // various pseudo-ops. Just return the # token and push back the following // token to be lexed next time. if (getLangOpts().AsmPreprocessor) { - Token *Toks = new Token[2]; + auto Toks = llvm::make_unique<Token[]>(2); // Return the # and the token after it. Toks[0] = SavedHash; Toks[1] = Result; @@ -920,7 +920,7 @@ void Preprocessor::HandleDirective(Token &Result) { // Enter this token stream so that we re-lex the tokens. Make sure to // enable macro expansion, in case the token after the # is an identifier // that is expanded. - EnterTokenStream(Toks, 2, false, true); + EnterTokenStream(std::move(Toks), 2, false); return; } @@ -1442,13 +1442,13 @@ static void EnterAnnotationToken(Preprocessor &PP, tok::TokenKind Kind, void *AnnotationVal) { // FIXME: Produce this as the current token directly, rather than // allocating a new token for it. - Token *Tok = new Token[1]; + auto Tok = llvm::make_unique<Token[]>(1); Tok[0].startToken(); Tok[0].setKind(Kind); Tok[0].setLocation(Begin); Tok[0].setAnnotationEndLoc(End); Tok[0].setAnnotationValue(AnnotationVal); - PP.EnterTokenStream(Tok, 1, true, true); + PP.EnterTokenStream(std::move(Tok), 1, true); } /// \brief Produce a diagnostic informing the user that a #include or similar diff --git a/clang/lib/Lex/PPMacroExpansion.cpp b/clang/lib/Lex/PPMacroExpansion.cpp index 11b4a0b3d8c..69f5bc8ddcc 100644 --- a/clang/lib/Lex/PPMacroExpansion.cpp +++ b/clang/lib/Lex/PPMacroExpansion.cpp @@ -755,13 +755,12 @@ MacroArgs *Preprocessor::ReadFunctionLikeMacroArgs(Token &MacroName, // Do not lose the EOF/EOD. Return it to the client. MacroName = Tok; return nullptr; - } else { - // Do not lose the EOF/EOD. - Token *Toks = new Token[1]; - Toks[0] = Tok; - EnterTokenStream(Toks, 1, true, true); - break; } + // Do not lose the EOF/EOD. + auto Toks = llvm::make_unique<Token[]>(1); + Toks[0] = Tok; + EnterTokenStream(std::move(Toks), 1, true); + break; } else if (Tok.is(tok::r_paren)) { // If we found the ) token, the macro arg list is done. if (NumParens-- == 0) { diff --git a/clang/lib/Lex/Pragma.cpp b/clang/lib/Lex/Pragma.cpp index afb41a24077..fea66daa5f8 100644 --- a/clang/lib/Lex/Pragma.cpp +++ b/clang/lib/Lex/Pragma.cpp @@ -938,13 +938,13 @@ struct PragmaDebugHandler : public PragmaHandler { } SourceLocation NameLoc = Tok.getLocation(); - Token *Toks = PP.getPreprocessorAllocator().Allocate<Token>(1); - Toks->startToken(); - Toks->setKind(tok::annot_pragma_captured); - Toks->setLocation(NameLoc); + MutableArrayRef<Token> Toks( + PP.getPreprocessorAllocator().Allocate<Token>(1), 1); + Toks[0].startToken(); + Toks[0].setKind(tok::annot_pragma_captured); + Toks[0].setLocation(NameLoc); - PP.EnterTokenStream(Toks, 1, /*DisableMacroExpansion=*/true, - /*OwnsTokens=*/false); + PP.EnterTokenStream(Toks, /*DisableMacroExpansion=*/true); } // Disable MSVC warning about runtime stack overflow. |