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

via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 6 02:15:24 PST 2025


Author: Utkarsh Saxena
Date: 2025-02-06T11:15:20+01:00
New Revision: 112490ce04edeb0b34ab2079b649e907c62fd47e

URL: https://github.com/llvm/llvm-project/commit/112490ce04edeb0b34ab2079b649e907c62fd47e
DIFF: https://github.com/llvm/llvm-project/commit/112490ce04edeb0b34ab2079b649e907c62fd47e.diff

LOG: [analyzer] Use getFileName and do not use realpath names (#126039)

The real paths resolves symlinks and makes the tests fail when the
filesystem is a symlink tree over a content-addressable storage (our
internal environment).

Added: 
    

Modified: 
    clang/lib/StaticAnalyzer/Core/BugReporter.cpp

Removed: 
    


################################################################################
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)


        


More information about the cfe-commits mailing list