[all-commits] [llvm/llvm-project] 676a96: [Parse] Remove TimeTraceScope for "ParseTemplate"
Fangrui Song via All-commits
all-commits at lists.llvm.org
Mon Apr 17 09:58:06 PDT 2023
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 676a96f768e1101ed5187c7751e56e1e11ebe593
https://github.com/llvm/llvm-project/commit/676a96f768e1101ed5187c7751e56e1e11ebe593
Author: Fangrui Song <i at maskray.me>
Date: 2023-04-17 (Mon, 17 Apr 2023)
Changed paths:
M clang/lib/Parse/ParseTemplate.cpp
Log Message:
-----------
[Parse] Remove TimeTraceScope for "ParseTemplate"
Fix https://github.com/llvm/llvm-project/issues/56554
```
#include "1.h"
#include "2.h"
int foo();
```
Suppose that 1.h ends with a template function. When parsing the function,
the `ParseFunctionDefinition` call after the TimeTraceScope object
may consume a `r_brace` token and lex the end of file (1.h), resulting
in an ExitFile event in SemaPPCallbacks::FileChanged. This event will call `llvm::timeTraceProfilerEnd();`,
which incorrectly ends "ParseTemplate" instead of "Source" (1.h).
Once 2.h has been fully parsed, the destructor of 1.h's TimeTraceScope object
will end "Source" (1.h).
This behavior erroneously extends the end of "Source" (1.h), which makes
"Source" (2.h) appear to be nested inside "Source" (1.h). This bug is difficult
to fix correctly in an elegant way, and we have two options: either end
"ParseTemplate" when ending "Source" (1.h), or delay the ExitFile event.
However, both approaches require complex code. For now, we can remove the
"ParseTemplate" TimeTraceScope. This can be re-added if properly repaired.
Reviewed By: anton-afanasyev
Differential Revision: https://reviews.llvm.org/D148410
More information about the All-commits
mailing list