[clang] [Clang] [Driver] Canoncalise `-internal-isystem` include paths (PR #148745)

via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 15 11:06:04 PDT 2025


================
@@ -1370,19 +1370,47 @@ ToolChain::CXXStdlibType ToolChain::GetCXXStdlibType(const ArgList &Args) const{
   return *cxxStdlibType;
 }
 
+static void ResolveAndAddSystemIncludePath(const ArgList &DriverArgs,
+                                           ArgStringList &CC1Args,
+                                           const Twine &Path) {
+  bool Canonicalize =
+      DriverArgs.hasFlag(options::OPT_canonical_prefixes,
+                         options::OPT_no_canonical_prefixes, true);
+
+  if (!Canonicalize) {
+    CC1Args.push_back(DriverArgs.MakeArgString(Path));
+    return;
+  }
+
+  // We canonicalise system include paths that were added automatically if
+  // that yields a shorter path since those can end up quite long otherwise.
+  //
+  // While we would ideally prefer to use FileManager for this, there doesn't
+  // seem to be a way to obtain one in here, so we just resolve these via the
+  // real file system; most system libraries will hopefully correspond to
+  // actual files.
+  IntrusiveRefCntPtr<vfs::FileSystem> VFS = vfs::getRealFileSystem();
+  SmallString<256> Canonical, PathStorage;
+  StringRef SimplifiedPath = Path.toStringRef(PathStorage);
+  if (!VFS->getRealPath(SimplifiedPath, Canonical) &&
+      Canonical.size() < SimplifiedPath.size())
----------------
Sirraide wrote:

Right, I guess we can just remove that now—that was more important when we were canonicalising *all* paths so we wouldn’t print the canonical path for files that the user specified (e.g. we wouldn’t want to print `/home/user/some_project/src/foo.cc` instead of just `foo.cc`), but I don’t think that’s really all that relevant anymore now for the kinds of paths that this is dealing w/; I’ll remove the check.

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


More information about the cfe-commits mailing list