From b183650d5a6085309481fc7fd7faeb0b0cb89828 Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Wed, 23 Apr 2014 00:15:01 +0000 Subject: [PATCH] Driver: Avoid a duplicate path separator and clean up code git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@206933 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Driver/WindowsToolChain.cpp | 36 +++++++++++++++++---------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/lib/Driver/WindowsToolChain.cpp b/lib/Driver/WindowsToolChain.cpp index a32a7bfe07..cd6d7e16fc 100644 --- a/lib/Driver/WindowsToolChain.cpp +++ b/lib/Driver/WindowsToolChain.cpp @@ -297,17 +297,12 @@ void Windows::AddClangSystemIncludeArgs(const ArgList &DriverArgs, // Honor %INCLUDE%. It should know essential search paths with vcvarsall.bat. if (const char *cl_include_dir = getenv("INCLUDE")) { SmallVector Dirs; - StringRef(cl_include_dir).split(Dirs, ";"); - int n = 0; - for (SmallVectorImpl::iterator I = Dirs.begin(), E = Dirs.end(); - I != E; ++I) { - StringRef d = *I; - if (d.size() == 0) - continue; - ++n; - addSystemInclude(DriverArgs, CC1Args, d); - } - if (n) return; + StringRef(cl_include_dir) + .split(Dirs, ";", /*MaxSplit=*/-1, /*KeepEmpty=*/false); + for (StringRef Dir : Dirs) + addSystemInclude(DriverArgs, CC1Args, Dir); + if (!Dirs.empty()) + return; } std::string VSDir; @@ -316,12 +311,19 @@ void Windows::AddClangSystemIncludeArgs(const ArgList &DriverArgs, // When built with access to the proper Windows APIs, try to actually find // the correct include paths first. if (getVisualStudioDir(VSDir)) { - addSystemInclude(DriverArgs, CC1Args, VSDir + "\\VC\\include"); - if (getWindowsSDKDir(WindowsSDKDir)) - addSystemInclude(DriverArgs, CC1Args, WindowsSDKDir + "\\include"); - else - addSystemInclude(DriverArgs, CC1Args, - VSDir + "\\VC\\PlatformSDK\\Include"); + SmallString<128> P; + P = VSDir; + llvm::sys::path::append(P, "VC\\include"); + addSystemInclude(DriverArgs, CC1Args, P.str()); + if (getWindowsSDKDir(WindowsSDKDir)) { + P = WindowsSDKDir; + llvm::sys::path::append(P, "include"); + addSystemInclude(DriverArgs, CC1Args, P.str()); + } else { + P = VSDir; + llvm::sys::path::append(P, "VC\\PlatformSDK\\Include"); + addSystemInclude(DriverArgs, CC1Args, P.str()); + } return; } -- 2.40.0