Author: Dawid Jurczak Date: 2022-02-28T20:43:28+01:00 New Revision: b3e2dac27c0cd4562e4ece5d5e24a1e59705c746
URL: https://github.com/llvm/llvm-project/commit/b3e2dac27c0cd4562e4ece5d5e24a1e59705c746 DIFF: https://github.com/llvm/llvm-project/commit/b3e2dac27c0cd4562e4ece5d5e24a1e59705c746.diff LOG: [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. Added: Modified: clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp clang/lib/Tooling/Inclusions/HeaderIncludes.cpp Removed: ################################################################################ diff --git a/clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp index b57c5dc6de562..361abf9b73493 100644 --- a/clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp @@ -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; diff --git a/clang/lib/Tooling/Inclusions/HeaderIncludes.cpp b/clang/lib/Tooling/Inclusions/HeaderIncludes.cpp index fbceb26c39c7c..fc8773e60c581 100644 --- a/clang/lib/Tooling/Inclusions/HeaderIncludes.cpp +++ b/clang/lib/Tooling/Inclusions/HeaderIncludes.cpp @@ -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); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits