[clang] Add source file name for template instantiations in -ftime-trace (PR #98320)

via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 10 08:55:30 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-driver

Author: Utkarsh Saxena (usx95)

<details>
<summary>Changes</summary>



---
Full diff: https://github.com/llvm/llvm-project/pull/98320.diff


3 Files Affected:

- (modified) clang/lib/Sema/SemaTemplateInstantiate.cpp (+1) 
- (modified) clang/lib/Sema/SemaTemplateInstantiateDecl.cpp (+1) 
- (modified) clang/test/Driver/ftime-trace-sections.py (+15-1) 


``````````diff
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index a7bc6749c5852..69f46a77d8067 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -3430,6 +3430,7 @@ Sema::InstantiateClass(SourceLocation PointOfInstantiation,
     llvm::raw_string_ostream OS(Name);
     Instantiation->getNameForDiagnostic(OS, getPrintingPolicy(),
                                         /*Qualified=*/true);
+    OS << "@" << SourceMgr.getFilename(Instantiation->getLocation());
     return Name;
   });
 
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 88f6af80cbc55..d835a217802ac 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -4966,6 +4966,7 @@ void Sema::InstantiateFunctionDefinition(SourceLocation PointOfInstantiation,
     llvm::raw_string_ostream OS(Name);
     Function->getNameForDiagnostic(OS, getPrintingPolicy(),
                                    /*Qualified=*/true);
+    OS << "@" << SourceMgr.getFilename(Function->getLocation());
     return Name;
   });
 
diff --git a/clang/test/Driver/ftime-trace-sections.py b/clang/test/Driver/ftime-trace-sections.py
index 02afa4ac54eb7..cfec77fc97a8e 100644
--- a/clang/test/Driver/ftime-trace-sections.py
+++ b/clang/test/Driver/ftime-trace-sections.py
@@ -1,6 +1,6 @@
 #!/usr/bin/env python
 
-import json, sys, time
+import json, sys, time, re
 
 
 def is_inside(range1, range2):
@@ -16,12 +16,18 @@ def is_before(range1, range2):
     c = range2["ts"]
     return b <= c
 
+instantiation_pattern = re.compile("^.*<.*>@.*.cpp$")
+
+def is_valid_instantiation(instantiation):
+    return instantiation_pattern.match(instantiation["args"]["detail"])
+
 
 log_contents = json.loads(sys.stdin.read())
 events = log_contents["traceEvents"]
 codegens = [event for event in events if event["name"] == "CodeGen Function"]
 frontends = [event for event in events if event["name"] == "Frontend"]
 backends = [event for event in events if event["name"] == "Backend"]
+instantiations = [event for event in events if event["name"].startswith("Instantiate")]
 
 beginning_of_time = log_contents["beginningOfTime"] / 1000000
 seconds_since_epoch = time.time()
@@ -48,3 +54,11 @@ def is_before(range1, range2):
     ]
 ):
     sys.exit("Not all Frontend section are before all Backend sections!")
+
+if not all(
+    [
+        is_valid_instantiation(instantiation)
+        for instantiation in instantiations
+    ]
+):
+    sys.exit("Not all Frontend section are before all Backend sections!")

``````````

</details>


https://github.com/llvm/llvm-project/pull/98320


More information about the cfe-commits mailing list