@@ -2404,19 +2404,36 @@ SourceManagerForFile::SourceManagerForFile(StringRef FileName,
24042404 SourceMgr->setMainFileID (ID);
24052405}
24062406
2407- StringRef SourceManager::getNameForDiagnostic (StringRef Filename) const {
2407+ StringRef
2408+ SourceManager::getNameForDiagnostic (StringRef Filename,
2409+ const DiagnosticOptions &Opts) const {
24082410 OptionalFileEntryRef File = getFileManager ().getOptionalFileRef (Filename);
24092411 if (!File)
24102412 return Filename;
24112413
2412- // Try to simplify paths that contain '..' in any case since paths to
2413- // standard library headers especially tend to get quite long otherwise.
2414- // Only do that for local filesystems though to avoid slowing down
2415- // compilation too much.
2416- bool Absolute = Diag.getDiagnosticOptions ().AbsolutePath ;
2417- bool AlwaysSimplify = File->getName ().contains (" .." ) &&
2418- llvm::sys::fs::is_local (File->getName ());
2419- if (!Absolute && !AlwaysSimplify)
2414+ bool SimplifyPath = [&] {
2415+ if (Opts.AbsolutePath )
2416+ return true ;
2417+
2418+ // Try to simplify paths that contain '..' in any case since paths to
2419+ // standard library headers especially tend to get quite long otherwise.
2420+ // Only do that for local filesystems though to avoid slowing down
2421+ // compilation too much.
2422+ if (!File->getName ().contains (" .." ))
2423+ return false ;
2424+
2425+ // If we're not on Windows, check if we're on a network file system and
2426+ // avoid simplifying the path in that case since that can be slow. On
2427+ // Windows, the check for a local filesystem is already slow, so skip it.
2428+ #ifndef _WIN32
2429+ if (!llvm::sys::fs::is_local (File->getName ()))
2430+ return false ;
2431+ #endif
2432+
2433+ return true ;
2434+ }();
2435+
2436+ if (!SimplifyPath)
24202437 return Filename;
24212438
24222439 // This may involve computing canonical names, so cache the result.
@@ -2451,7 +2468,7 @@ StringRef SourceManager::getNameForDiagnostic(StringRef Filename) const {
24512468 // In some cases, the resolved path may actually end up being longer (e.g.
24522469 // if it was originally a relative path), so just retain whichever one
24532470 // ends up being shorter.
2454- if (!Absolute && TempBuf.size () > Filename.size ())
2471+ if (!Opts. AbsolutePath && TempBuf.size () > Filename.size ())
24552472 CacheEntry = Filename;
24562473 else
24572474 CacheEntry = TempBuf.str ().copy (DiagNameAlloc);
0 commit comments