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

James Y Knight via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 15 10:47:39 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())
----------------
jyknight wrote:

Should it really be conditional on length? That seems kinda weird to me.

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


More information about the cfe-commits mailing list