[PATCH] D148410: [Parse] Remove TimeTraceScope for "ParseTemplate"

Fangrui Song via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 14 22:36:59 PDT 2023


MaskRay created this revision.
MaskRay added reviewers: clang, MaggieYi, aras-p, anton-afanasyev.
Herald added a project: All.
MaskRay requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148410

Files:
  clang/lib/Parse/ParseTemplate.cpp


Index: clang/lib/Parse/ParseTemplate.cpp
===================================================================
--- clang/lib/Parse/ParseTemplate.cpp
+++ clang/lib/Parse/ParseTemplate.cpp
@@ -281,12 +281,6 @@
     return nullptr;
   }
 
-  llvm::TimeTraceScope TimeScope("ParseTemplate", [&]() {
-    return std::string(DeclaratorInfo.getIdentifier() != nullptr
-                           ? DeclaratorInfo.getIdentifier()->getName()
-                           : "<unknown>");
-  });
-
   LateParsedAttrList LateParsedAttrs(true);
   if (DeclaratorInfo.isFunctionDeclarator()) {
     if (Tok.is(tok::kw_requires)) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D148410.513843.patch
Type: text/x-patch
Size: 614 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230415/8b0fb7f8/attachment.bin>


More information about the cfe-commits mailing list