aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/SemaModule.cpp
diff options
context:
space:
mode:
authoryronglin <yronglin777@gmail.com>2025-06-26 08:49:43 +0800
committerGitHub <noreply@github.com>2025-06-26 08:49:43 +0800
commit0529a346007cecab95c6820a60cb3e4e36f34990 (patch)
treed3fbf476f06d373422bfafadd3696067faf801b2 /clang/lib/Sema/SemaModule.cpp
parent63b14b3f2bf6abd96d9a6cf0cec9e9447b7a3744 (diff)
downloadllvm-0529a346007cecab95c6820a60cb3e4e36f34990.zip
llvm-0529a346007cecab95c6820a60cb3e4e36f34990.tar.gz
llvm-0529a346007cecab95c6820a60cb3e4e36f34990.tar.bz2
[clang][Preprocessor] Handle the first pp-token in EnterMainSourceFile (#145244)
Depends on [[clang][Preprocessor] Add peekNextPPToken, makes look ahead next token without side-effects](https://github.com/llvm/llvm-project/pull/143898). This PR fix the performance regression that introduced in https://github.com/llvm/llvm-project/pull/144233. The original PR(https://github.com/llvm/llvm-project/pull/144233) handle the first pp-token in the main source file in the macro definition/expansion and `Lexer::Lex`, but the lexer is almost always on the hot path, we may hit a performance regression. In this PR, we handle the first pp-token in `Preprocessor::EnterMainSourceFile`. --------- Signed-off-by: yronglin <yronglin777@gmail.com>
Diffstat (limited to 'clang/lib/Sema/SemaModule.cpp')
-rw-r--r--clang/lib/Sema/SemaModule.cpp8
1 files changed, 3 insertions, 5 deletions
diff --git a/clang/lib/Sema/SemaModule.cpp b/clang/lib/Sema/SemaModule.cpp
index fe70ce3..7c982bc 100644
--- a/clang/lib/Sema/SemaModule.cpp
+++ b/clang/lib/Sema/SemaModule.cpp
@@ -337,11 +337,9 @@ Sema::ActOnModuleDecl(SourceLocation StartLoc, SourceLocation ModuleLoc,
// tokens in a file (excluding the global module fragment.).
if (getLangOpts().CPlusPlusModules && !IntroducerIsFirstPPToken && !SeenGMF) {
Diag(ModuleLoc, diag::err_module_decl_not_at_start);
- SourceLocation BeginLoc = PP.getMainFileFirstPPToken().getLocation();
- if (BeginLoc.isValid()) {
- Diag(BeginLoc, diag::note_global_module_introducer_missing)
- << FixItHint::CreateInsertion(BeginLoc, "module;\n");
- }
+ SourceLocation BeginLoc = PP.getMainFileFirstPPTokenLoc();
+ Diag(BeginLoc, diag::note_global_module_introducer_missing)
+ << FixItHint::CreateInsertion(BeginLoc, "module;\n");
}
// C++23 [module.unit]p1: ... The identifiers module and import shall not