r260246 - Simplify EnterTokenStream API to make it more robust for memory management
David Blaikie via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 9 10:52:10 PST 2016
Author: dblaikie
Date: Tue Feb 9 12:52:09 2016
New Revision: 260246
URL: http://llvm.org/viewvc/llvm-project?rev=260246&view=rev
Log:
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)
Modified:
cfe/trunk/include/clang/Lex/Preprocessor.h
cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp
cfe/trunk/lib/Lex/PPDirectives.cpp
cfe/trunk/lib/Lex/PPMacroExpansion.cpp
cfe/trunk/lib/Lex/Pragma.cpp
cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/lib/Parse/ParseExprCXX.cpp
cfe/trunk/lib/Parse/ParseObjc.cpp
cfe/trunk/lib/Parse/ParsePragma.cpp
cfe/trunk/lib/Parse/ParseStmtAsm.cpp
cfe/trunk/lib/Parse/ParseTemplate.cpp
cfe/trunk/lib/Rewrite/HTMLRewrite.cpp
Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=260246&r1=260245&r2=260246&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Tue Feb 9 12:52:09 2016
@@ -1018,10 +1018,20 @@ public:
/// If \p OwnsTokens is false, this method assumes that the specified stream
/// of tokens has a permanent owner somewhere, so they do not need to be
/// copied. If it is true, it assumes the array of tokens is allocated with
- /// \c new[] and must be freed.
+ /// \c new[] and the Preprocessor will delete[] it.
+private:
void EnterTokenStream(const Token *Toks, unsigned NumToks,
bool DisableMacroExpansion, bool OwnsTokens);
+public:
+ void EnterTokenStream(std::unique_ptr<Token[]> Toks, unsigned NumToks,
+ bool DisableMacroExpansion) {
+ EnterTokenStream(Toks.release(), NumToks, DisableMacroExpansion, true);
+ }
+ void EnterTokenStream(ArrayRef<Token> Toks, bool DisableMacroExpansion) {
+ EnterTokenStream(Toks.data(), Toks.size(), DisableMacroExpansion, false);
+ }
+
/// \brief Pop the current lexer/macro exp off the top of the lexer stack.
///
/// This should only be used in situations where the current state of the
Modified: cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp?rev=260246&r1=260245&r2=260246&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp (original)
+++ cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp Tue Feb 9 12:52:09 2016
@@ -580,11 +580,10 @@ struct UnknownPragmaHandler : public Pra
if (ShouldExpandTokens) {
// The first token does not have expanded macros. Expand them, if
// required.
- Token *Toks = new Token[1];
+ auto Toks = llvm::make_unique<Token[]>(1);
Toks[0] = PragmaTok;
- PP.EnterTokenStream(Toks, /*NumToks=*/1,
- /*DisableMacroExpansion=*/false,
- /*OwnsTokens=*/true);
+ PP.EnterTokenStream(std::move(Toks), /*NumToks=*/1,
+ /*DisableMacroExpansion=*/false);
PP.Lex(PragmaTok);
}
Token PrevToken;
Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=260246&r1=260245&r2=260246&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Tue Feb 9 12:52:09 2016
@@ -907,7 +907,7 @@ void Preprocessor::HandleDirective(Token
// 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
// 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(Preproc
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
Modified: cfe/trunk/lib/Lex/PPMacroExpansion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPMacroExpansion.cpp?rev=260246&r1=260245&r2=260246&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPMacroExpansion.cpp (original)
+++ cfe/trunk/lib/Lex/PPMacroExpansion.cpp Tue Feb 9 12:52:09 2016
@@ -755,13 +755,12 @@ MacroArgs *Preprocessor::ReadFunctionLik
// 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) {
Modified: cfe/trunk/lib/Lex/Pragma.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Pragma.cpp?rev=260246&r1=260245&r2=260246&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Pragma.cpp (original)
+++ cfe/trunk/lib/Lex/Pragma.cpp Tue Feb 9 12:52:09 2016
@@ -938,13 +938,13 @@ struct PragmaDebugHandler : public Pragm
}
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.
Modified: cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp?rev=260246&r1=260245&r2=260246&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp (original)
+++ cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp Tue Feb 9 12:52:09 2016
@@ -325,7 +325,7 @@ void Parser::ParseLexedMethodDeclaration
// Parse the default argument from its saved token stream.
Toks->push_back(Tok); // So that the current token doesn't get lost
- PP.EnterTokenStream(&Toks->front(), Toks->size(), true, false);
+ PP.EnterTokenStream(*Toks, true);
// Consume the previously-pushed token.
ConsumeAnyToken();
@@ -399,7 +399,7 @@ void Parser::ParseLexedMethodDeclaration
// Parse the default argument from its saved token stream.
Toks->push_back(Tok); // So that the current token doesn't get lost
- PP.EnterTokenStream(&Toks->front(), Toks->size(), true, false);
+ PP.EnterTokenStream(*Toks, true);
// Consume the previously-pushed token.
ConsumeAnyToken();
@@ -504,7 +504,7 @@ void Parser::ParseLexedMethodDef(LexedMe
// Append the current token at the end of the new token stream so that it
// doesn't get lost.
LM.Toks.push_back(Tok);
- PP.EnterTokenStream(LM.Toks.data(), LM.Toks.size(), true, false);
+ PP.EnterTokenStream(LM.Toks, true);
// Consume the previously pushed token.
ConsumeAnyToken(/*ConsumeCodeCompletionTok=*/true);
@@ -617,7 +617,7 @@ void Parser::ParseLexedMemberInitializer
// Append the current token at the end of the new token stream so that it
// doesn't get lost.
MI.Toks.push_back(Tok);
- PP.EnterTokenStream(MI.Toks.data(), MI.Toks.size(), true, false);
+ PP.EnterTokenStream(MI.Toks, true);
// Consume the previously pushed token.
ConsumeAnyToken(/*ConsumeCodeCompletionTok=*/true);
@@ -971,10 +971,10 @@ public:
// Put back the original tokens.
Self.SkipUntil(EndKind, StopAtSemi | StopBeforeMatch);
if (Toks.size()) {
- Token *Buffer = new Token[Toks.size()];
- std::copy(Toks.begin() + 1, Toks.end(), Buffer);
+ auto Buffer = llvm::make_unique<Token[]>(Toks.size());
+ std::copy(Toks.begin() + 1, Toks.end(), Buffer.get());
Buffer[Toks.size() - 1] = Self.Tok;
- Self.PP.EnterTokenStream(Buffer, Toks.size(), true, /*Owned*/true);
+ Self.PP.EnterTokenStream(std::move(Buffer), Toks.size(), true);
Self.Tok = Toks.front();
}
Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=260246&r1=260245&r2=260246&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Tue Feb 9 12:52:09 2016
@@ -1187,7 +1187,7 @@ void Parser::ParseLexedAttribute(LatePar
// Append the current token at the end of the new token stream so that it
// doesn't get lost.
LA.Toks.push_back(Tok);
- PP.EnterTokenStream(LA.Toks.data(), LA.Toks.size(), true, false);
+ PP.EnterTokenStream(LA.Toks, true);
// Consume the previously pushed token.
ConsumeAnyToken(/*ConsumeCodeCompletionTok=*/true);
Modified: cfe/trunk/lib/Parse/ParseExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExprCXX.cpp?rev=260246&r1=260245&r2=260246&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseExprCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExprCXX.cpp Tue Feb 9 12:52:09 2016
@@ -3093,8 +3093,7 @@ Parser::ParseCXXAmbiguousParenExpression
Toks.push_back(Tok);
// Re-enter the stored parenthesized tokens into the token stream, so we may
// parse them now.
- PP.EnterTokenStream(Toks.data(), Toks.size(),
- true/*DisableMacroExpansion*/, false/*OwnsTokens*/);
+ PP.EnterTokenStream(Toks, true /*DisableMacroExpansion*/);
// Drop the current token and bring the first cached one. It's the same token
// as when we entered this function.
ConsumeAnyToken();
Modified: cfe/trunk/lib/Parse/ParseObjc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseObjc.cpp?rev=260246&r1=260245&r2=260246&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/lib/Parse/ParseObjc.cpp Tue Feb 9 12:52:09 2016
@@ -3585,8 +3585,8 @@ void Parser::ParseLexedObjCMethodDefs(Le
// Append the current token at the end of the new token stream so that it
// doesn't get lost.
LM.Toks.push_back(Tok);
- PP.EnterTokenStream(LM.Toks.data(), LM.Toks.size(), true, false);
-
+ PP.EnterTokenStream(LM.Toks, true);
+
// Consume the previously pushed token.
ConsumeAnyToken(/*ConsumeCodeCompletionTok=*/true);
Modified: cfe/trunk/lib/Parse/ParsePragma.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParsePragma.cpp?rev=260246&r1=260245&r2=260246&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParsePragma.cpp (original)
+++ cfe/trunk/lib/Parse/ParsePragma.cpp Tue Feb 9 12:52:09 2016
@@ -507,8 +507,9 @@ void Parser::HandlePragmaMSVtorDisp() {
void Parser::HandlePragmaMSPragma() {
assert(Tok.is(tok::annot_pragma_ms_pragma));
// Grab the tokens out of the annotation and enter them into the stream.
- auto TheTokens = (std::pair<Token*, size_t> *)Tok.getAnnotationValue();
- PP.EnterTokenStream(TheTokens->first, TheTokens->second, true, true);
+ auto TheTokens =
+ (std::pair<std::unique_ptr<Token[]>, size_t> *)Tok.getAnnotationValue();
+ PP.EnterTokenStream(std::move(TheTokens->first), TheTokens->second, true);
SourceLocation PragmaLocation = ConsumeToken(); // The annotation token.
assert(Tok.isAnyIdentifier());
StringRef PragmaName = Tok.getIdentifierInfo()->getName();
@@ -798,14 +799,13 @@ bool Parser::HandlePragmaLoopHint(LoopHi
Hint.OptionLoc = IdentifierLoc::create(
Actions.Context, Info->Option.getLocation(), OptionInfo);
- const Token *Toks = Info->Toks.data();
- size_t TokSize = Info->Toks.size();
+ llvm::ArrayRef<Token> Toks = Info->Toks;
// Return a valid hint if pragma unroll or nounroll were specified
// without an argument.
bool PragmaUnroll = PragmaNameInfo->getName() == "unroll";
bool PragmaNoUnroll = PragmaNameInfo->getName() == "nounroll";
- if (TokSize == 0 && (PragmaUnroll || PragmaNoUnroll)) {
+ if (Toks.empty() && (PragmaUnroll || PragmaNoUnroll)) {
ConsumeToken(); // The annotation token.
Hint.Range = Info->PragmaName.getLocation();
return true;
@@ -813,7 +813,7 @@ bool Parser::HandlePragmaLoopHint(LoopHi
// The constant expression is always followed by an eof token, which increases
// the TokSize by 1.
- assert(TokSize > 0 &&
+ assert(!Toks.empty() &&
"PragmaLoopHintInfo::Toks must contain at least one token.");
// If no option is specified the argument is assumed to be a constant expr.
@@ -849,14 +849,13 @@ bool Parser::HandlePragmaLoopHint(LoopHi
<< /*FullKeyword=*/OptionUnroll;
return false;
}
- if (TokSize > 2)
+ if (Toks.size() > 2)
Diag(Tok.getLocation(), diag::warn_pragma_extra_tokens_at_eol)
<< PragmaLoopHintString(Info->PragmaName, Info->Option);
Hint.StateLoc = IdentifierLoc::create(Actions.Context, StateLoc, StateInfo);
} else {
// Enter constant expression including eof terminator into token stream.
- PP.EnterTokenStream(Toks, TokSize, /*DisableMacroExpansion=*/false,
- /*OwnsTokens=*/false);
+ PP.EnterTokenStream(Toks, /*DisableMacroExpansion=*/false);
ConsumeToken(); // The annotation token.
ExprResult R = ParseConstantExpression();
@@ -881,7 +880,7 @@ bool Parser::HandlePragmaLoopHint(LoopHi
}
Hint.Range = SourceRange(Info->PragmaName.getLocation(),
- Info->Toks[TokSize - 1].getLocation());
+ Info->Toks.back().getLocation());
return true;
}
@@ -934,15 +933,14 @@ void PragmaGCCVisibilityHandler::HandleP
return;
}
- Token *Toks = new Token[1];
+ auto Toks = llvm::make_unique<Token[]>(1);
Toks[0].startToken();
Toks[0].setKind(tok::annot_pragma_vis);
Toks[0].setLocation(VisLoc);
Toks[0].setAnnotationEndLoc(EndLoc);
Toks[0].setAnnotationValue(
const_cast<void*>(static_cast<const void*>(VisType)));
- PP.EnterTokenStream(Toks, 1, /*DisableMacroExpansion=*/true,
- /*OwnsTokens=*/true);
+ PP.EnterTokenStream(std::move(Toks), 1, /*DisableMacroExpansion=*/true);
}
// #pragma pack(...) comes in the following delicious flavors:
@@ -1041,27 +1039,22 @@ void PragmaPackHandler::HandlePragma(Pre
return;
}
- PragmaPackInfo *Info =
- (PragmaPackInfo*) PP.getPreprocessorAllocator().Allocate(
- sizeof(PragmaPackInfo), llvm::alignOf<PragmaPackInfo>());
- new (Info) PragmaPackInfo();
+ PragmaPackInfo *Info =
+ PP.getPreprocessorAllocator().Allocate<PragmaPackInfo>(1);
Info->Kind = Kind;
Info->Name = Name;
Info->Alignment = Alignment;
Info->LParenLoc = LParenLoc;
Info->RParenLoc = RParenLoc;
- Token *Toks =
- (Token*) PP.getPreprocessorAllocator().Allocate(
- sizeof(Token) * 1, llvm::alignOf<Token>());
- new (Toks) Token();
+ MutableArrayRef<Token> Toks(PP.getPreprocessorAllocator().Allocate<Token>(1),
+ 1);
Toks[0].startToken();
Toks[0].setKind(tok::annot_pragma_pack);
Toks[0].setLocation(PackLoc);
Toks[0].setAnnotationEndLoc(RParenLoc);
Toks[0].setAnnotationValue(static_cast<void*>(Info));
- PP.EnterTokenStream(Toks, 1, /*DisableMacroExpansion=*/true,
- /*OwnsTokens=*/false);
+ PP.EnterTokenStream(Toks, /*DisableMacroExpansion=*/true);
}
// #pragma ms_struct on
@@ -1096,18 +1089,15 @@ void PragmaMSStructHandler::HandlePragma
return;
}
- Token *Toks =
- (Token*) PP.getPreprocessorAllocator().Allocate(
- sizeof(Token) * 1, llvm::alignOf<Token>());
- new (Toks) Token();
+ MutableArrayRef<Token> Toks(PP.getPreprocessorAllocator().Allocate<Token>(1),
+ 1);
Toks[0].startToken();
Toks[0].setKind(tok::annot_pragma_msstruct);
Toks[0].setLocation(MSStructTok.getLocation());
Toks[0].setAnnotationEndLoc(EndLoc);
Toks[0].setAnnotationValue(reinterpret_cast<void*>(
static_cast<uintptr_t>(Kind)));
- PP.EnterTokenStream(Toks, 1, /*DisableMacroExpansion=*/true,
- /*OwnsTokens=*/false);
+ PP.EnterTokenStream(Toks, /*DisableMacroExpansion=*/true);
}
// #pragma 'align' '=' {'native','natural','mac68k','power','reset'}
@@ -1167,18 +1157,15 @@ static void ParseAlignPragma(Preprocesso
return;
}
- Token *Toks =
- (Token*) PP.getPreprocessorAllocator().Allocate(
- sizeof(Token) * 1, llvm::alignOf<Token>());
- new (Toks) Token();
+ MutableArrayRef<Token> Toks(PP.getPreprocessorAllocator().Allocate<Token>(1),
+ 1);
Toks[0].startToken();
Toks[0].setKind(tok::annot_pragma_align);
Toks[0].setLocation(FirstTok.getLocation());
Toks[0].setAnnotationEndLoc(EndLoc);
Toks[0].setAnnotationValue(reinterpret_cast<void*>(
static_cast<uintptr_t>(Kind)));
- PP.EnterTokenStream(Toks, 1, /*DisableMacroExpansion=*/true,
- /*OwnsTokens=*/false);
+ PP.EnterTokenStream(Toks, /*DisableMacroExpansion=*/true);
}
void PragmaAlignHandler::HandlePragma(Preprocessor &PP,
@@ -1260,9 +1247,9 @@ void PragmaUnusedHandler::HandlePragma(P
// This allows us to cache a "#pragma unused" that occurs inside an inline
// C++ member function.
- Token *Toks =
- (Token*) PP.getPreprocessorAllocator().Allocate(
- sizeof(Token) * 2 * Identifiers.size(), llvm::alignOf<Token>());
+ MutableArrayRef<Token> Toks(
+ PP.getPreprocessorAllocator().Allocate<Token>(2 * Identifiers.size()),
+ 2 * Identifiers.size());
for (unsigned i=0; i != Identifiers.size(); i++) {
Token &pragmaUnusedTok = Toks[2*i], &idTok = Toks[2*i+1];
pragmaUnusedTok.startToken();
@@ -1270,8 +1257,7 @@ void PragmaUnusedHandler::HandlePragma(P
pragmaUnusedTok.setLocation(UnusedLoc);
idTok = Identifiers[i];
}
- PP.EnterTokenStream(Toks, 2*Identifiers.size(),
- /*DisableMacroExpansion=*/true, /*OwnsTokens=*/false);
+ PP.EnterTokenStream(Toks, /*DisableMacroExpansion=*/true);
}
// #pragma weak identifier
@@ -1311,9 +1297,8 @@ void PragmaWeakHandler::HandlePragma(Pre
}
if (HasAlias) {
- Token *Toks =
- (Token*) PP.getPreprocessorAllocator().Allocate(
- sizeof(Token) * 3, llvm::alignOf<Token>());
+ MutableArrayRef<Token> Toks(
+ PP.getPreprocessorAllocator().Allocate<Token>(3), 3);
Token &pragmaUnusedTok = Toks[0];
pragmaUnusedTok.startToken();
pragmaUnusedTok.setKind(tok::annot_pragma_weakalias);
@@ -1321,20 +1306,17 @@ void PragmaWeakHandler::HandlePragma(Pre
pragmaUnusedTok.setAnnotationEndLoc(AliasName.getLocation());
Toks[1] = WeakName;
Toks[2] = AliasName;
- PP.EnterTokenStream(Toks, 3,
- /*DisableMacroExpansion=*/true, /*OwnsTokens=*/false);
+ PP.EnterTokenStream(Toks, /*DisableMacroExpansion=*/true);
} else {
- Token *Toks =
- (Token*) PP.getPreprocessorAllocator().Allocate(
- sizeof(Token) * 2, llvm::alignOf<Token>());
+ MutableArrayRef<Token> Toks(
+ PP.getPreprocessorAllocator().Allocate<Token>(2), 2);
Token &pragmaUnusedTok = Toks[0];
pragmaUnusedTok.startToken();
pragmaUnusedTok.setKind(tok::annot_pragma_weak);
pragmaUnusedTok.setLocation(WeakLoc);
pragmaUnusedTok.setAnnotationEndLoc(WeakLoc);
Toks[1] = WeakName;
- PP.EnterTokenStream(Toks, 2,
- /*DisableMacroExpansion=*/true, /*OwnsTokens=*/false);
+ PP.EnterTokenStream(Toks, /*DisableMacroExpansion=*/true);
}
}
@@ -1370,9 +1352,8 @@ void PragmaRedefineExtnameHandler::Handl
return;
}
- Token *Toks =
- (Token*) PP.getPreprocessorAllocator().Allocate(
- sizeof(Token) * 3, llvm::alignOf<Token>());
+ MutableArrayRef<Token> Toks(PP.getPreprocessorAllocator().Allocate<Token>(3),
+ 3);
Token &pragmaRedefTok = Toks[0];
pragmaRedefTok.startToken();
pragmaRedefTok.setKind(tok::annot_pragma_redefine_extname);
@@ -1380,8 +1361,7 @@ void PragmaRedefineExtnameHandler::Handl
pragmaRedefTok.setAnnotationEndLoc(AliasName.getLocation());
Toks[1] = RedefName;
Toks[2] = AliasName;
- PP.EnterTokenStream(Toks, 3,
- /*DisableMacroExpansion=*/true, /*OwnsTokens=*/false);
+ PP.EnterTokenStream(Toks, /*DisableMacroExpansion=*/true);
}
@@ -1393,18 +1373,15 @@ PragmaFPContractHandler::HandlePragma(Pr
if (PP.LexOnOffSwitch(OOS))
return;
- Token *Toks =
- (Token*) PP.getPreprocessorAllocator().Allocate(
- sizeof(Token) * 1, llvm::alignOf<Token>());
- new (Toks) Token();
+ MutableArrayRef<Token> Toks(PP.getPreprocessorAllocator().Allocate<Token>(1),
+ 1);
Toks[0].startToken();
Toks[0].setKind(tok::annot_pragma_fp_contract);
Toks[0].setLocation(Tok.getLocation());
Toks[0].setAnnotationEndLoc(Tok.getLocation());
Toks[0].setAnnotationValue(reinterpret_cast<void*>(
static_cast<uintptr_t>(OOS)));
- PP.EnterTokenStream(Toks, 1, /*DisableMacroExpansion=*/true,
- /*OwnsTokens=*/false);
+ PP.EnterTokenStream(Toks, /*DisableMacroExpansion=*/true);
}
void
@@ -1452,17 +1429,14 @@ PragmaOpenCLExtensionHandler::HandlePrag
}
OpenCLExtData data(ename, state);
- Token *Toks =
- (Token*) PP.getPreprocessorAllocator().Allocate(
- sizeof(Token) * 1, llvm::alignOf<Token>());
- new (Toks) Token();
+ MutableArrayRef<Token> Toks(PP.getPreprocessorAllocator().Allocate<Token>(1),
+ 1);
Toks[0].startToken();
Toks[0].setKind(tok::annot_pragma_opencl_extension);
Toks[0].setLocation(NameLoc);
Toks[0].setAnnotationValue(data.getOpaqueValue());
Toks[0].setAnnotationEndLoc(StateLoc);
- PP.EnterTokenStream(Toks, 1, /*DisableMacroExpansion=*/true,
- /*OwnsTokens=*/false);
+ PP.EnterTokenStream(Toks, /*DisableMacroExpansion=*/true);
if (PP.getPPCallbacks())
PP.getPPCallbacks()->PragmaOpenCLExtension(NameLoc, ename,
@@ -1506,10 +1480,10 @@ PragmaOpenMPHandler::HandlePragma(Prepro
Tok.setLocation(EodLoc);
Pragma.push_back(Tok);
- Token *Toks = new Token[Pragma.size()];
- std::copy(Pragma.begin(), Pragma.end(), Toks);
- PP.EnterTokenStream(Toks, Pragma.size(),
- /*DisableMacroExpansion=*/false, /*OwnsTokens=*/true);
+ auto Toks = llvm::make_unique<Token[]>(Pragma.size());
+ std::copy(Pragma.begin(), Pragma.end(), Toks.get());
+ PP.EnterTokenStream(std::move(Toks), Pragma.size(),
+ /*DisableMacroExpansion=*/false);
}
/// \brief Handle '#pragma pointers_to_members'
@@ -1725,10 +1699,11 @@ void PragmaMSPragma::HandlePragma(Prepro
TokenVector.push_back(EoF);
// We must allocate this array with new because EnterTokenStream is going to
// delete it later.
- Token *TokenArray = new Token[TokenVector.size()];
- std::copy(TokenVector.begin(), TokenVector.end(), TokenArray);
+ auto TokenArray = llvm::make_unique<Token[]>(TokenVector.size());
+ std::copy(TokenVector.begin(), TokenVector.end(), TokenArray.get());
auto Value = new (PP.getPreprocessorAllocator())
- std::pair<Token*, size_t>(std::make_pair(TokenArray, TokenVector.size()));
+ std::pair<std::unique_ptr<Token[]>, size_t>(std::move(TokenArray),
+ TokenVector.size());
AnnotTok.setAnnotationValue(Value);
PP.EnterToken(AnnotTok);
}
@@ -2059,12 +2034,11 @@ void PragmaLoopHintHandler::HandlePragma
return;
}
- Token *TokenArray = new Token[TokenList.size()];
- std::copy(TokenList.begin(), TokenList.end(), TokenArray);
+ auto TokenArray = llvm::make_unique<Token[]>(TokenList.size());
+ std::copy(TokenList.begin(), TokenList.end(), TokenArray.get());
- PP.EnterTokenStream(TokenArray, TokenList.size(),
- /*DisableMacroExpansion=*/false,
- /*OwnsTokens=*/true);
+ PP.EnterTokenStream(std::move(TokenArray), TokenList.size(),
+ /*DisableMacroExpansion=*/false);
}
/// \brief Handle the loop unroll optimization pragmas.
@@ -2127,12 +2101,12 @@ void PragmaUnrollHintHandler::HandlePrag
}
// Generate the hint token.
- Token *TokenArray = new Token[1];
+ auto TokenArray = llvm::make_unique<Token[]>(1);
TokenArray[0].startToken();
TokenArray[0].setKind(tok::annot_pragma_loop_hint);
TokenArray[0].setLocation(PragmaName.getLocation());
TokenArray[0].setAnnotationEndLoc(PragmaName.getLocation());
TokenArray[0].setAnnotationValue(static_cast<void *>(Info));
- PP.EnterTokenStream(TokenArray, 1, /*DisableMacroExpansion=*/false,
- /*OwnsTokens=*/true);
+ PP.EnterTokenStream(std::move(TokenArray), 1,
+ /*DisableMacroExpansion=*/false);
}
Modified: cfe/trunk/lib/Parse/ParseStmtAsm.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseStmtAsm.cpp?rev=260246&r1=260245&r2=260246&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseStmtAsm.cpp (original)
+++ cfe/trunk/lib/Parse/ParseStmtAsm.cpp Tue Feb 9 12:52:09 2016
@@ -200,9 +200,7 @@ ExprResult Parser::ParseMSAsmIdentifier(
// Also copy the current token over.
LineToks.push_back(Tok);
- PP.EnterTokenStream(LineToks.begin(), LineToks.size(),
- /*disable macros*/ true,
- /*owns tokens*/ false);
+ PP.EnterTokenStream(LineToks, /*DisableMacroExpansions*/ true);
// Clear the current token and advance to the first token in LineToks.
ConsumeAnyToken();
Modified: cfe/trunk/lib/Parse/ParseTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseTemplate.cpp?rev=260246&r1=260245&r2=260246&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseTemplate.cpp (original)
+++ cfe/trunk/lib/Parse/ParseTemplate.cpp Tue Feb 9 12:52:09 2016
@@ -1369,7 +1369,7 @@ void Parser::ParseLateTemplatedFuncDef(L
// Append the current token at the end of the new token stream so that it
// doesn't get lost.
LPT.Toks.push_back(Tok);
- PP.EnterTokenStream(LPT.Toks.data(), LPT.Toks.size(), true, false);
+ PP.EnterTokenStream(LPT.Toks, true);
// Consume the previously pushed token.
ConsumeAnyToken(/*ConsumeCodeCompletionTok=*/true);
Modified: cfe/trunk/lib/Rewrite/HTMLRewrite.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Rewrite/HTMLRewrite.cpp?rev=260246&r1=260245&r2=260246&view=diff
==============================================================================
--- cfe/trunk/lib/Rewrite/HTMLRewrite.cpp (original)
+++ cfe/trunk/lib/Rewrite/HTMLRewrite.cpp Tue Feb 9 12:52:09 2016
@@ -502,7 +502,7 @@ void html::HighlightMacros(Rewriter &R,
// Enter the tokens we just lexed. This will cause them to be macro expanded
// but won't enter sub-files (because we removed #'s).
- TmpPP.EnterTokenStream(&TokenStream[0], TokenStream.size(), false, false);
+ TmpPP.EnterTokenStream(TokenStream, false);
TokenConcatenation ConcatInfo(TmpPP);
More information about the cfe-commits
mailing list