Mercurial > hg > CbC > CbC_llvm
diff clang/lib/Lex/TokenLexer.cpp @ 252:1f2b6ac9f198 llvm-original
LLVM16-1
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 18 Aug 2023 09:04:13 +0900 |
parents | c4bab56944e8 |
children |
line wrap: on
line diff
--- a/clang/lib/Lex/TokenLexer.cpp Wed Nov 09 17:47:54 2022 +0900 +++ b/clang/lib/Lex/TokenLexer.cpp Fri Aug 18 09:04:13 2023 +0900 @@ -31,6 +31,7 @@ #include "llvm/ADT/iterator_range.h" #include <cassert> #include <cstring> +#include <optional> using namespace clang; @@ -204,7 +205,7 @@ assert(CurTokenIdx != 0 && "Can not have __VAOPT__ contents begin with a ##"); Token &LHS = VAOPTTokens[CurTokenIdx - 1]; - pasteTokens(LHS, llvm::makeArrayRef(VAOPTTokens, NumVAOptTokens), + pasteTokens(LHS, llvm::ArrayRef(VAOPTTokens, NumVAOptTokens), CurTokenIdx); // Replace the token prior to the first ## in this iteration. ConcatenatedVAOPTResultToks.back() = LHS; @@ -248,7 +249,7 @@ // we install the newly expanded sequence as the new 'Tokens' list. bool MadeChange = false; - Optional<bool> CalledWithVariadicArguments; + std::optional<bool> CalledWithVariadicArguments; VAOptExpansionContext VCtx(PP); @@ -499,8 +500,7 @@ // the first token in a __VA_OPT__ after a ##, delete the ##. assert(VCtx.isInVAOpt() && "should only happen inside a __VA_OPT__"); VCtx.hasPlaceholderAfterHashhashAtStart(); - } - if (RParenAfter) + } else if (RParenAfter) VCtx.hasPlaceholderBeforeRParen(); } continue; @@ -566,7 +566,7 @@ continue; } - if (RParenAfter) + if (RParenAfter && !NonEmptyPasteBefore) VCtx.hasPlaceholderBeforeRParen(); // If this is on the RHS of a paste operator, we've already copied the @@ -722,7 +722,7 @@ } bool TokenLexer::pasteTokens(Token &Tok) { - return pasteTokens(Tok, llvm::makeArrayRef(Tokens, NumTokens), CurTokenIdx); + return pasteTokens(Tok, llvm::ArrayRef(Tokens, NumTokens), CurTokenIdx); } /// LHSTok is the LHS of a ## operator, and CurTokenIdx is the ## @@ -1019,8 +1019,16 @@ SourceLocation Limit = SM.getComposedLoc(BeginFID, SM.getFileIDSize(BeginFID)); Partition = All.take_while([&](const Token &T) { - return T.getLocation() >= BeginLoc && T.getLocation() < Limit && - NearLast(T.getLocation()); + // NOTE: the Limit is included! The lexer recovery only ever inserts a + // single token past the end of the FileID, specifically the ) when a + // macro-arg containing a comma should be guarded by parentheses. + // + // It is safe to include the Limit here because SourceManager allocates + // FileSize + 1 for each SLocEntry. + // + // See https://github.com/llvm/llvm-project/issues/60722. + return T.getLocation() >= BeginLoc && T.getLocation() <= Limit + && NearLast(T.getLocation()); }); } assert(!Partition.empty());