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
This commit is contained in:
David Blaikie 2016-02-09 18:52:09 +00:00
parent cb1175c7db
commit 2eabcc988f
13 changed files with 99 additions and 120 deletions

View File

@ -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

View File

@ -580,11 +580,10 @@ struct UnknownPragmaHandler : public PragmaHandler {
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;

View File

@ -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

View File

@ -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) {

View File

@ -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.

View File

@ -325,7 +325,7 @@ void Parser::ParseLexedMethodDeclaration(LateParsedMethodDeclaration &LM) {
// 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(LateParsedMethodDeclaration &LM) {
// 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(LexedMethod &LM) {
// 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(LateParsedMemberInitializer &MI) {
// 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();
}

View File

@ -1187,7 +1187,7 @@ void Parser::ParseLexedAttribute(LateParsedAttribute &LA,
// 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);

View File

@ -3093,8 +3093,7 @@ Parser::ParseCXXAmbiguousParenExpression(ParenParseOption &ExprType,
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();

View File

@ -3585,8 +3585,8 @@ void Parser::ParseLexedObjCMethodDefs(LexedMethod &LM, bool parseMethod) {
// 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);

View File

@ -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(LoopHint &Hint) {
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(LoopHint &Hint) {
// 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(LoopHint &Hint) {
<< /*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(LoopHint &Hint) {
}
Hint.Range = SourceRange(Info->PragmaName.getLocation(),
Info->Toks[TokSize - 1].getLocation());
Info->Toks.back().getLocation());
return true;
}
@ -934,15 +933,14 @@ void PragmaGCCVisibilityHandler::HandlePragma(Preprocessor &PP,
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(Preprocessor &PP,
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(Preprocessor &PP,
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(Preprocessor &PP, Token &FirstTok,
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(Preprocessor &PP,
// 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(Preprocessor &PP,
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(Preprocessor &PP,
}
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(Preprocessor &PP,
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::HandlePragma(Preprocessor &PP,
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::HandlePragma(Preprocessor &PP,
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(Preprocessor &PP,
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::HandlePragma(Preprocessor &PP,
}
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(Preprocessor &PP,
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(Preprocessor &PP,
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(Preprocessor &PP,
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::HandlePragma(Preprocessor &PP,
}
// 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);
}

View File

@ -200,9 +200,7 @@ ExprResult Parser::ParseMSAsmIdentifier(llvm::SmallVectorImpl<Token> &LineToks,
// 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();

View File

@ -1369,7 +1369,7 @@ void Parser::ParseLateTemplatedFuncDef(LateParsedTemplate &LPT) {
// 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);

View File

@ -502,7 +502,7 @@ void html::HighlightMacros(Rewriter &R, FileID FID, const Preprocessor& PP) {
// 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);