[clang] [analyzer] Use getFileName and do not use realpath names (PR #126039)

via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 6 01:49:52 PST 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-static-analyzer-1

Author: Utkarsh Saxena (usx95)

<details>
<summary>Changes</summary>



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


1 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Core/BugReporter.cpp (+6-6) 


``````````diff
diff --git a/clang/lib/StaticAnalyzer/Core/BugReporter.cpp b/clang/lib/StaticAnalyzer/Core/BugReporter.cpp
index 4100812c4623e90..13677ed341d0c4c 100644
--- a/clang/lib/StaticAnalyzer/Core/BugReporter.cpp
+++ b/clang/lib/StaticAnalyzer/Core/BugReporter.cpp
@@ -299,7 +299,8 @@ std::string timeTraceName(const BugReportEquivClass &EQ) {
   return ("Flushing EQC " + BT.getDescription()).str();
 }
 
-llvm::TimeTraceMetadata timeTraceMetadata(const BugReportEquivClass &EQ) {
+llvm::TimeTraceMetadata timeTraceMetadata(const BugReportEquivClass &EQ,
+                                          const SourceManager &SM) {
   // Must be called only when constructing non-bogus TimeTraceScope
   assert(llvm::timeTraceProfilerEnabled());
 
@@ -309,9 +310,7 @@ llvm::TimeTraceMetadata timeTraceMetadata(const BugReportEquivClass &EQ) {
   const BugReport *R = BugReports.front().get();
   const auto &BT = R->getBugType();
   auto Loc = R->getLocation().asLocation();
-  std::string File = "";
-  if (const auto *Entry = Loc.getFileEntry())
-    File = Entry->tryGetRealPathName().str();
+  std::string File = SM.getFilename(Loc).str();
   return {BT.getCheckerName().str(), std::move(File),
           static_cast<int>(Loc.getLineNumber())};
 }
@@ -3150,8 +3149,9 @@ BugReport *PathSensitiveBugReporter::findReportInEquivalenceClass(
 }
 
 void BugReporter::FlushReport(BugReportEquivClass &EQ) {
-  llvm::TimeTraceScope TCS{timeTraceName(EQ),
-                           [&EQ]() { return timeTraceMetadata(EQ); }};
+  llvm::TimeTraceScope TCS{timeTraceName(EQ), [&]() {
+                             return timeTraceMetadata(EQ, getSourceManager());
+                           }};
   SmallVector<BugReport*, 10> bugReports;
   BugReport *report = findReportInEquivalenceClass(EQ, bugReports);
   if (!report)

``````````

</details>


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


More information about the cfe-commits mailing list