aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Basic/SourceManager.cpp
diff options
context:
space:
mode:
authorSirraide <aeternalmail@gmail.com>2025-07-12 15:13:22 +0200
committerGitHub <noreply@github.com>2025-07-12 15:13:22 +0200
commit7b43c6c6a729bde8b20143f9620e6323812f1694 (patch)
treed5470bb83b3a1fd6565bb3b3d412dbdcc37da689 /clang/lib/Basic/SourceManager.cpp
parentbd7a6bfdf4d71f62ce7b536d543592ce73646366 (diff)
downloadllvm-7b43c6c6a729bde8b20143f9620e6323812f1694.zip
llvm-7b43c6c6a729bde8b20143f9620e6323812f1694.tar.gz
llvm-7b43c6c6a729bde8b20143f9620e6323812f1694.tar.bz2
Revert "[Clang] [Diagnostics] Simplify filenames that contain '..'" (#148367)
Revert llvm/llvm-project#143520 for now since it’s causing issues for people who are using symlinks and prefer to preserve the original path (i.e. looks like we’ll have to make this configurable after all; I just need to figure out how to pass `-no-canonical-prefixes` down through the driver); I’m planning to refactor this a bit and reland it in a few days.
Diffstat (limited to 'clang/lib/Basic/SourceManager.cpp')
-rw-r--r--clang/lib/Basic/SourceManager.cpp72
1 files changed, 0 insertions, 72 deletions
diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp
index e6b6130..b2b1488 100644
--- a/clang/lib/Basic/SourceManager.cpp
+++ b/clang/lib/Basic/SourceManager.cpp
@@ -2390,75 +2390,3 @@ SourceManagerForFile::SourceManagerForFile(StringRef FileName,
assert(ID.isValid());
SourceMgr->setMainFileID(ID);
}
-
-StringRef
-SourceManager::getNameForDiagnostic(StringRef Filename,
- const DiagnosticOptions &Opts) const {
- OptionalFileEntryRef File = getFileManager().getOptionalFileRef(Filename);
- if (!File)
- return Filename;
-
- bool SimplifyPath = [&] {
- if (Opts.AbsolutePath)
- return true;
-
- // Try to simplify paths that contain '..' in any case since paths to
- // standard library headers especially tend to get quite long otherwise.
- // Only do that for local filesystems though to avoid slowing down
- // compilation too much.
- if (!File->getName().contains(".."))
- return false;
-
- // If we're not on Windows, check if we're on a network file system and
- // avoid simplifying the path in that case since that can be slow. On
- // Windows, the check for a local filesystem is already slow, so skip it.
-#ifndef _WIN32
- if (!llvm::sys::fs::is_local(File->getName()))
- return false;
-#endif
-
- return true;
- }();
-
- if (!SimplifyPath)
- return Filename;
-
- // This may involve computing canonical names, so cache the result.
- StringRef &CacheEntry = DiagNames[Filename];
- if (!CacheEntry.empty())
- return CacheEntry;
-
- // We want to print a simplified absolute path, i. e. without "dots".
- //
- // The hardest part here are the paths like "<part1>/<link>/../<part2>".
- // On Unix-like systems, we cannot just collapse "<link>/..", because
- // paths are resolved sequentially, and, thereby, the path
- // "<part1>/<part2>" may point to a different location. That is why
- // we use FileManager::getCanonicalName(), which expands all indirections
- // with llvm::sys::fs::real_path() and caches the result.
- //
- // On the other hand, it would be better to preserve as much of the
- // original path as possible, because that helps a user to recognize it.
- // real_path() expands all links, which sometimes too much. Luckily,
- // on Windows we can just use llvm::sys::path::remove_dots(), because,
- // on that system, both aforementioned paths point to the same place.
- SmallString<256> TempBuf;
-#ifdef _WIN32
- TempBuf = File->getName();
- llvm::sys::fs::make_absolute(TempBuf);
- llvm::sys::path::native(TempBuf);
- llvm::sys::path::remove_dots(TempBuf, /* remove_dot_dot */ true);
-#else
- TempBuf = getFileManager().getCanonicalName(*File);
-#endif
-
- // In some cases, the resolved path may actually end up being longer (e.g.
- // if it was originally a relative path), so just retain whichever one
- // ends up being shorter.
- if (!Opts.AbsolutePath && TempBuf.size() > Filename.size())
- CacheEntry = Filename;
- else
- CacheEntry = TempBuf.str().copy(DiagNameAlloc);
-
- return CacheEntry;
-}