@@ -1370,19 +1370,48 @@ ToolChain::CXXStdlibType ToolChain::GetCXXStdlibType(const ArgList &Args) const{
13701370 return *cxxStdlibType;
13711371}
13721372
1373+
1374+ static void ResolveAndAddSystemIncludePath (const ArgList &DriverArgs,
1375+ ArgStringList &CC1Args,
1376+ const Twine &Path) {
1377+ bool Canonicalize =
1378+ DriverArgs.hasFlag (options::OPT_canonical_prefixes,
1379+ options::OPT_no_canonical_prefixes, true );
1380+
1381+ if (!Canonicalize) {
1382+ CC1Args.push_back (DriverArgs.MakeArgString (Path));
1383+ return ;
1384+ }
1385+
1386+ // We canonicalise system include paths that were added automatically if
1387+ // that yields a shorter path since those can end up quite long otherwise.
1388+ //
1389+ // While we would ideally prefer to use FileManager for this, there doesn't
1390+ // seem to be a way to obtain one in here, so we just resolve these via the
1391+ // real file system; most system libraries will hopefully correspond to
1392+ // actual files.
1393+ IntrusiveRefCntPtr<vfs::FileSystem> VFS = vfs::getRealFileSystem ();
1394+ SmallString<256 > Canonical, PathStorage;
1395+ StringRef SimplifiedPath = Path.toStringRef (PathStorage);
1396+ if (!VFS->getRealPath (SimplifiedPath, Canonical) &&
1397+ Canonical.size () < SimplifiedPath.size ())
1398+ SimplifiedPath = Canonical;
1399+ CC1Args.push_back (DriverArgs.MakeArgString (SimplifiedPath));
1400+ }
1401+
13731402// / Utility function to add a system framework directory to CC1 arguments.
13741403void ToolChain::addSystemFrameworkInclude (const llvm::opt::ArgList &DriverArgs,
13751404 llvm::opt::ArgStringList &CC1Args,
13761405 const Twine &Path) {
13771406 CC1Args.push_back (" -internal-iframework" );
1378- CC1Args. push_back (DriverArgs. MakeArgString ( Path) );
1407+ ResolveAndAddSystemIncludePath (DriverArgs, CC1Args, Path);
13791408}
13801409
13811410// / Utility function to add a system include directory to CC1 arguments.
13821411void ToolChain::addSystemInclude (const ArgList &DriverArgs,
13831412 ArgStringList &CC1Args, const Twine &Path) {
13841413 CC1Args.push_back (" -internal-isystem" );
1385- CC1Args. push_back (DriverArgs. MakeArgString ( Path) );
1414+ ResolveAndAddSystemIncludePath (DriverArgs, CC1Args, Path);
13861415}
13871416
13881417// / Utility function to add a system include directory with extern "C"
@@ -1397,7 +1426,7 @@ void ToolChain::addExternCSystemInclude(const ArgList &DriverArgs,
13971426 ArgStringList &CC1Args,
13981427 const Twine &Path) {
13991428 CC1Args.push_back (" -internal-externc-isystem" );
1400- CC1Args. push_back (DriverArgs. MakeArgString ( Path) );
1429+ ResolveAndAddSystemIncludePath (DriverArgs, CC1Args, Path);
14011430}
14021431
14031432void ToolChain::addExternCSystemIncludeIfExists (const ArgList &DriverArgs,
@@ -1411,20 +1440,16 @@ void ToolChain::addExternCSystemIncludeIfExists(const ArgList &DriverArgs,
14111440void ToolChain::addSystemFrameworkIncludes (const ArgList &DriverArgs,
14121441 ArgStringList &CC1Args,
14131442 ArrayRef<StringRef> Paths) {
1414- for (const auto &Path : Paths) {
1415- CC1Args.push_back (" -internal-iframework" );
1416- CC1Args.push_back (DriverArgs.MakeArgString (Path));
1417- }
1443+ for (const auto &Path : Paths)
1444+ addSystemFrameworkInclude (DriverArgs, CC1Args, Path);
14181445}
14191446
14201447// / Utility function to add a list of system include directories to CC1.
14211448void ToolChain::addSystemIncludes (const ArgList &DriverArgs,
14221449 ArgStringList &CC1Args,
14231450 ArrayRef<StringRef> Paths) {
1424- for (const auto &Path : Paths) {
1425- CC1Args.push_back (" -internal-isystem" );
1426- CC1Args.push_back (DriverArgs.MakeArgString (Path));
1427- }
1451+ for (const auto &Path : Paths)
1452+ addSystemInclude (DriverArgs, CC1Args, Path);
14281453}
14291454
14301455std::string ToolChain::concat (StringRef Path, const Twine &A, const Twine &B,
0 commit comments