[NFC] Don't pass temporary LangOptions to Lexer

Since https://reviews.llvm.org/D120334 we shouldn't pass temporary LangOptions to Lexer.
This change fixes stack-use-after-scope UB in LocalizationChecker found by sanitizer-x86_64-linux-fast buildbot
and resolve similar issue in HeaderIncludes.
This commit is contained in:
Dawid Jurczak 2022-02-28 20:14:44 +01:00
parent 517171ce20
commit b3e2dac27c
2 changed files with 4 additions and 3 deletions

View file

@ -1145,8 +1145,8 @@ void EmptyLocalizationContextChecker::MethodCrawler::VisitObjCMessageExpr(
Mgr.getSourceManager().getBufferOrNone(SLInfo.first, SL);
if (!BF)
return;
Lexer TheLexer(SL, LangOptions(), BF->getBufferStart(),
LangOptions LangOpts;
Lexer TheLexer(SL, LangOpts, BF->getBufferStart(),
BF->getBufferStart() + SLInfo.second, BF->getBufferEnd());
Token I;

View file

@ -43,8 +43,9 @@ unsigned getOffsetAfterTokenSequence(
GetOffsetAfterSequence) {
SourceManagerForFile VirtualSM(FileName, Code);
SourceManager &SM = VirtualSM.get();
LangOptions LangOpts = createLangOpts();
Lexer Lex(SM.getMainFileID(), SM.getBufferOrFake(SM.getMainFileID()), SM,
createLangOpts());
LangOpts);
Token Tok;
// Get the first token.
Lex.LexFromRawLexer(Tok);