Re: [PATCH] D12695: [Driver] Use UniversalCRT on Windows if available

2015-09-11 Thread İsmail Dönmez via cfe-commits
This doesn't seem to work here, VS 2015 on Win 10 x64:

C:\Users\ismail\Desktop>clang-cl.exe -fms-compatibility-version=19 foo.cpp
LINK : fatal error LNK1104: cannot open file 'kernel32.lib'
clang-cl.exe: error: linker command failed with exit code 1104 (use -v
to see invocation)

Works fine after setting LIB.

On Fri, Sep 11, 2015 at 3:11 AM, Reid Kleckner via cfe-commits
 wrote:
> This revision was automatically updated to reflect the committed changes.
> Closed by commit rL247362: [Driver] Use UniversalCRT on Windows if available 
> (authored by rnk).
>
> Changed prior to commit:
>   http://reviews.llvm.org/D12695?vs=34475=34515#toc
>
> Repository:
>   rL LLVM
>
> http://reviews.llvm.org/D12695
>
> Files:
>   cfe/trunk/lib/Driver/MSVCToolChain.cpp
>   cfe/trunk/lib/Driver/ToolChains.h
>   cfe/trunk/lib/Driver/Tools.cpp
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D12695: [Driver] Use UniversalCRT on Windows if available

2015-09-11 Thread İsmail Dönmez via cfe-commits
Hi,

C:\Users\ismail\Desktop>set include
INCLUDE=C:\Program Files (x86)\Microsoft Visual Studio
14.0\VC\INCLUDE;C:\Program Files (x86)\Microsoft Visual Studio
14.0\VC\ATLMFC\INCLUDE;C:\Program Files (x86)\Windows
Kits\10\include\10.0.10240.0\ucrt;C:\Program Files (x86)\Windows
Kits\NETFXSDK\4.6\include\um;C:\Program Files (x86)\Windows
Kits\10\include\10.0.10240.0\shared;C:\Program Files (x86)\Windows
Kits\10\include\10.0.10240.0\um;C:\Program Files (x86)\Windows
Kits\10\include\10.0.10240.0\winrt;

C:\Users\ismail\Desktop>set lib
LIB=C:\Program Files (x86)\Microsoft Visual Studio
14.0\VC\LIB\amd64;C:\Program Files (x86)\Microsoft Visual Studio
14.0\VC\ATLMFC\LIB\amd64;C:\Program Files (x86)\Windows
Kits\10\lib\10.0.10240.0\ucrt\x64;C:\Program Files (x86)\Windows
Kits\NETFXSDK\4.6\lib\um\x64;C:\Program Files (x86)\Windows
Kits\10\lib\10.0.10240.0\um\x64;
LIBPATH=C:\WINDOWS\Microsoft.NET\Framework64\v4.0.30319;C:\Program
Files (x86)\Microsoft Visual Studio 14.0\VC\LIB\amd64;C:\Program Files
(x86)\Microsoft Visual Studio 14.0\VC\ATLMFC\LIB\amd64;C:\Program
Files (x86)\Windows Kits\10\UnionMetadata;C:\Program Files
(x86)\Windows Kits\10\References;C:\Program Files (x86)\Windows
Kits\10\References\Windows.Foundation.UniversalApiContract\1.0.0.0;C:\Program
Files (x86)\Windows
Kits\10\References\Windows.Foundation.FoundationContract\1.0.0.0;C:\Program
Files (x86)\Windows
Kits\10\References\indows.Networking.Connectivity.WwanContract\1.0.0.0;C:\Program
Files (x86)\Microsoft SDKs\Windows
Kits\10\ExtensionSDKs\Microsoft.VCLibs\14.0\References\CommonConfiguration\neutral;

C:\Users\ismail\Desktop>clang-cl.exe -###
-fms-compatibility-version=19 mandelbrot-mp.cpp
clang version 3.8.0 (http://llvm.org/git/clang
d2dc884a74b40711955713829e7a09b8ff5ca1bc) (http://llvm.org/git/llvm
595af7ed8595ccf005efb087b5bb7d9a19e50e3b)
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files\LLVM\bin
 "C:\\Program Files\\LLVM\\bin\\clang-cl.exe" "-cc1" "-triple"
"x86_64-pc-windows-msvc19.0.0" "-emit-obj" "-mrelax-all"
"-disable-free" "-main-file-name" "mandelbrot-mp.cpp"
"-mrelocation-model" "pic" "-pic-level" "2" "-mthread-model" "posix"
"-relaxed-aliasing" "-fmath-errno" "-masm-verbose"
"-mconstructor-aliases" "-munwind-tables" "-target-cpu" "x86-64"
"-D_MT" "--dependent-lib=libcmt" "--dependent-lib=oldnames"
"-fms-volatile" "-fdiagnostics-format" "msvc"
"-momit-leaf-frame-pointer" "-dwarf-column-info" "-resource-dir"
"C:\\Program Files\\LLVM\\bin\\..\\lib\\clang\\3.8.0"
"-internal-isystem" "C:\\Program
Files\\LLVM\\bin\\..\\lib\\clang\\3.8.0\\include" "-internal-isystem"
"C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\INCLUDE"
"-internal-isystem" "C:\\Program Files (x86)\\Microsoft Visual Studio
14.0\\VC\\ATLMFC\\INCLUDE" "-internal-isystem" "C:\\Program Files
(x86)\\Windows Kits\\10\\include\\10.0.10240.0\\ucrt"
"-internal-isystem" "C:\\Program Files (x86)\\Windows
Kits\\NETFXSDK\\4.6\\include\\um" "-internal-isystem" "C:\\Program
Files (x86)\\Windows Kits\\10\\include\\10.0.10240.0\\shared"
"-internal-isystem" "C:\\Program Files (x86)\\Windows
Kits\\10\\include\\10.0.10240.0\\um" "-internal-isystem" "C:\\Program
Files (x86)\\Windows Kits\\10\\include\\10.0.10240.0\\winrt" "-Wall"
"-fdeprecated-macro" "-fdebug-compilation-dir"
"C:\\Users\\ismail\\Desktop" "-ferror-limit" "19" "-fmessage-length"
"100" "-mstackrealign" "-fms-extensions" "-fms-compatibility"
"-fms-compatibility-version=19" "-std=c++14"
"-fdelayed-template-parsing" "-fobjc-runtime=gcc"
"-fdiagnostics-show-option" "-fcolor-diagnostics" "-o"
"C:\\Users\\ismail\\AppData\\Local\\Temp\\mandelbrot-mp-d6f68c.obj"
"-x" "c++" "mandelbrot-mp.cpp"
 "C:\\Program Files (x86)\\Microsoft Visual Studio
14.0\\VC\\bin\\amd64\\link.exe" "-out:mandelbrot-mp.exe" "-nologo"
"C:\\Users\\ismail\\AppData\\Local\\Temp\\mandelbrot-mp-d6f68c.obj"


On Fri, Sep 11, 2015 at 4:42 PM, Igor Kudrin  wrote:
> Please, can you show the output of the following commands:
>
> 1) set include
> 2) set lib
> 3) clang-cl.exe -### -fms-compatibility-version=19 foo.cpp
>
>
> On 11.09.2015 17:44, İsmail Dönmez wrote:
>>
>> This doesn't seem to work here, VS 2015 on Win 10 x64:
>>
>> C:\Users\ismail\Desktop>clang-cl.exe -fms-compatibility-version=19 foo.cpp
>> LINK : fatal error LNK1104: cannot open file 'kernel32.lib'
>> clang-cl.exe: error: linker command failed with exit code 1104 (use -v
>> to see invocation)
>>
>> Works fine after setting LIB.
>>
>> On Fri, Sep 11, 2015 at 3:11 AM, Reid Kleckner via cfe-commits
>>  wrote:
>>>
>>> This revision was automatically updated to reflect the committed changes.
>>> Closed by commit rL247362: [Driver] Use UniversalCRT on Windows if
>>> available (authored by rnk).
>>>
>>> Changed prior to commit:
>>>http://reviews.llvm.org/D12695?vs=34475=34515#toc
>>>
>>> Repository:
>>>rL LLVM
>>>
>>> http://reviews.llvm.org/D12695
>>>
>>> Files:
>>>cfe/trunk/lib/Driver/MSVCToolChain.cpp

Re: [PATCH] D12695: [Driver] Use UniversalCRT on Windows if available

2015-09-11 Thread Igor Kudrin via cfe-commits

Please, can you show the output of the following commands:

1) set include
2) set lib
3) clang-cl.exe -### -fms-compatibility-version=19 foo.cpp

On 11.09.2015 17:44, İsmail Dönmez wrote:

This doesn't seem to work here, VS 2015 on Win 10 x64:

C:\Users\ismail\Desktop>clang-cl.exe -fms-compatibility-version=19 foo.cpp
LINK : fatal error LNK1104: cannot open file 'kernel32.lib'
clang-cl.exe: error: linker command failed with exit code 1104 (use -v
to see invocation)

Works fine after setting LIB.

On Fri, Sep 11, 2015 at 3:11 AM, Reid Kleckner via cfe-commits
 wrote:

This revision was automatically updated to reflect the committed changes.
Closed by commit rL247362: [Driver] Use UniversalCRT on Windows if available 
(authored by rnk).

Changed prior to commit:
   http://reviews.llvm.org/D12695?vs=34475=34515#toc

Repository:
   rL LLVM

http://reviews.llvm.org/D12695

Files:
   cfe/trunk/lib/Driver/MSVCToolChain.cpp
   cfe/trunk/lib/Driver/ToolChains.h
   cfe/trunk/lib/Driver/Tools.cpp


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D12695: [Driver] Use UniversalCRT on Windows if available

2015-09-10 Thread Reid Kleckner via cfe-commits
rnk added a comment.

There's a bunch of whitespace issues that clang-format can resolve. We also 
have the convention that variables are StudlyCaps, which isn't followed in a 
few places.

Do you need someone to commit this for you? If so, I can patch this in, test it 
manually, and deal with the style stuff if you deal with the VSDir part.



Comment at: lib/Driver/MSVCToolChain.cpp:293
@@ +292,3 @@
+// specific header files. If not, they are probably shipped with Universal CRT.
+bool clang::driver::toolchains::MSVCToolChain::useUniversalCRT() const
+{

This should really take VSDir as a parameter instead of recomputing it, since 
all the callers are already computing it.


http://reviews.llvm.org/D12695



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D12695: [Driver] Use UniversalCRT on Windows if available

2015-09-10 Thread Igor Kudrin via cfe-commits
ikudrin added a comment.

In http://reviews.llvm.org/D12695#243552, @rnk wrote:

> There's a bunch of whitespace issues that clang-format can resolve.


Thanks! I'll reformat it.

> We also have the convention that variables are StudlyCaps, which isn't 
> followed in a few places.


I've tried to follow the style of the source file. Do you think I should force 
this rule here?

> Do you need someone to commit this for you? If so, I can patch this in, test 
> it manually, and deal with the style stuff if you deal with the VSDir part.


I'd really appreciate it. I'll prepare a new version in a few minutes.


http://reviews.llvm.org/D12695



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D12695: [Driver] Use UniversalCRT on Windows if available

2015-09-10 Thread Igor Kudrin via cfe-commits
ikudrin marked an inline comment as done.
ikudrin added a comment.

In http://reviews.llvm.org/D12695#243320, @rnk wrote:

> FYI @ruiu is moving this code to LLVM in http://reviews.llvm.org/D12604.


Thanks. I think I'll move my changes to the new place when he's finished.


http://reviews.llvm.org/D12695



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D12695: [Driver] Use UniversalCRT on Windows if available

2015-09-10 Thread Reid Kleckner via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL247362: [Driver] Use UniversalCRT on Windows if available 
(authored by rnk).

Changed prior to commit:
  http://reviews.llvm.org/D12695?vs=34475=34515#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D12695

Files:
  cfe/trunk/lib/Driver/MSVCToolChain.cpp
  cfe/trunk/lib/Driver/ToolChains.h
  cfe/trunk/lib/Driver/Tools.cpp

Index: cfe/trunk/lib/Driver/MSVCToolChain.cpp
===
--- cfe/trunk/lib/Driver/MSVCToolChain.cpp
+++ cfe/trunk/lib/Driver/MSVCToolChain.cpp
@@ -205,6 +205,21 @@
 #endif // USE_WIN32
 }
 
+// Convert LLVM's ArchType
+// to the corresponding name of Windows SDK libraries subfolder
+static StringRef getWindowsSDKArch(llvm::Triple::ArchType Arch) {
+  switch (Arch) {
+  case llvm::Triple::x86:
+return "x86";
+  case llvm::Triple::x86_64:
+return "x64";
+  case llvm::Triple::arm:
+return "arm";
+  default:
+return "";
+  }
+}
+
 /// \brief Get Windows SDK installation directory.
 bool MSVCToolChain::getWindowsSDKDir(std::string , int ,
  int ) const {
@@ -263,26 +278,75 @@
 if (!found)
   return false;
 
-llvm::sys::path::append(libPath, "um");
-switch (getArch()) {
-case llvm::Triple::x86:
-  llvm::sys::path::append(libPath, "x86");
-  break;
-case llvm::Triple::x86_64:
-  llvm::sys::path::append(libPath, "x64");
-  break;
-case llvm::Triple::arm:
-  llvm::sys::path::append(libPath, "arm");
-  break;
-default:
+const StringRef archName = getWindowsSDKArch(getArch());
+if (archName.empty())
   return false;
-}
+llvm::sys::path::append(libPath, "um", archName);
   }
 
   path = libPath.str();
   return true;
 }
 
+// Check if the Include path of a specified version of Visual Studio contains
+// specific header files. If not, they are probably shipped with Universal CRT.
+bool clang::driver::toolchains::MSVCToolChain::useUniversalCRT(
+std::string ) const {
+  llvm::SmallString<128> TestPath(VisualStudioDir);
+  llvm::sys::path::append(TestPath, "VC\\include\\stdlib.h");
+
+  return !llvm::sys::fs::exists(TestPath);
+}
+
+bool MSVCToolChain::getUniversalCRTSdkDir(std::string ,
+  std::string ) const {
+  // vcvarsqueryregistry.bat for Visual Studio 2015 queries the registry
+  // for the specific key "KitsRoot10". So do we.
+  if (!getSystemRegistryString(
+  "SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots", "KitsRoot10",
+  Path, nullptr))
+return false;
+
+  UCRTVersion.clear();
+
+  // Find the most recent version of Universal CRT.
+  // vcvarsqueryregistry.bat sorts entries in the include directory by names and
+  // uses the last one of the list.
+  // So we compare entry names lexicographically to find the greatest one.
+  std::error_code EC;
+  llvm::SmallString<128> IncludePath(Path);
+  llvm::sys::path::append(IncludePath, "Include");
+  for (llvm::sys::fs::directory_iterator DirIt(IncludePath, EC), DirEnd;
+   DirIt != DirEnd && !EC; DirIt.increment(EC)) {
+if (!llvm::sys::fs::is_directory(DirIt->path()))
+  continue;
+StringRef CandidateName = llvm::sys::path::filename(DirIt->path());
+if (CandidateName > UCRTVersion)
+  UCRTVersion = CandidateName;
+  }
+
+  return !UCRTVersion.empty();
+}
+
+bool MSVCToolChain::getUniversalCRTLibraryPath(std::string ) const {
+  std::string UniversalCRTSdkPath;
+  std::string UCRTVersion;
+
+  Path.clear();
+  if (!getUniversalCRTSdkDir(UniversalCRTSdkPath, UCRTVersion))
+return false;
+
+  StringRef ArchName = getWindowsSDKArch(getArch());
+  if (ArchName.empty())
+return false;
+
+  llvm::SmallString<128> LibPath(UniversalCRTSdkPath);
+  llvm::sys::path::append(LibPath, "Lib", UCRTVersion, "ucrt", ArchName);
+
+  Path = LibPath.str();
+  return true;
+}
+
 // Get the location to use for Visual Studio binaries.  The location priority
 // is: %VCINSTALLDIR% > %PATH% > newest copy of Visual Studio installed on
 // system (as reported by the registry).
@@ -460,6 +524,17 @@
   if (getVisualStudioInstallDir(VSDir)) {
 AddSystemIncludeWithSubfolder(DriverArgs, CC1Args, VSDir, "VC\\include");
 
+if (useUniversalCRT(VSDir)) {
+  std::string UniversalCRTSdkPath;
+  std::string UCRTVersion;
+  if (getUniversalCRTSdkDir(UniversalCRTSdkPath, UCRTVersion)) {
+llvm::SmallString<128> UCRTIncludePath(UniversalCRTSdkPath);
+llvm::sys::path::append(UCRTIncludePath, "Include", UCRTVersion,
+"ucrt");
+addSystemInclude(DriverArgs, CC1Args, UCRTIncludePath);
+  }
+}
+
 std::string WindowsSDKDir;
 int major, minor;
 if (getWindowsSDKDir(WindowsSDKDir, major, minor)) {
Index: cfe/trunk/lib/Driver/ToolChains.h
===
--- 

Re: [PATCH] D12695: [Driver] Use UniversalCRT on Windows if available

2015-09-10 Thread Igor Kudrin via cfe-commits
ikudrin updated this revision to Diff 34475.
ikudrin added a comment.

- Fixed formatting issues.
- Normalized VariableNames.
- Reworked the useUniversalCRT method to receive a path of Visual Studio.


http://reviews.llvm.org/D12695

Files:
  lib/Driver/MSVCToolChain.cpp
  lib/Driver/ToolChains.h
  lib/Driver/Tools.cpp

Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -8951,6 +8951,13 @@
   }
   CmdArgs.push_back(
   Args.MakeArgString(std::string("-libpath:") + LibDir.c_str()));
+
+  if (MSVC.useUniversalCRT(VisualStudioDir)) {
+std::string UniversalCRTLibPath;
+if (MSVC.getUniversalCRTLibraryPath(UniversalCRTLibPath))
+  CmdArgs.push_back(Args.MakeArgString(std::string("-libpath:") +
+   UniversalCRTLibPath.c_str()));
+  }
 }
 
 std::string WindowsSdkLibPath;
Index: lib/Driver/ToolChains.h
===
--- lib/Driver/ToolChains.h
+++ lib/Driver/ToolChains.h
@@ -840,6 +840,10 @@
 
   bool getWindowsSDKDir(std::string , int , int ) const;
   bool getWindowsSDKLibraryPath(std::string ) const;
+  /// \brief Check if Universal CRT should be used if available
+  bool useUniversalCRT(std::string ) const;
+  bool getUniversalCRTSdkDir(std::string , std::string ) const;
+  bool getUniversalCRTLibraryPath(std::string ) const;
   bool getVisualStudioInstallDir(std::string ) const;
   bool getVisualStudioBinariesFolder(const char *clangProgramPath,
  std::string ) const;
Index: lib/Driver/MSVCToolChain.cpp
===
--- lib/Driver/MSVCToolChain.cpp
+++ lib/Driver/MSVCToolChain.cpp
@@ -205,6 +205,21 @@
 #endif // USE_WIN32
 }
 
+// Convert LLVM's ArchType
+// to the corresponding name of Windows SDK libraries subfolder
+static StringRef getWindowsSDKArch(llvm::Triple::ArchType Arch) {
+  switch (Arch) {
+  case llvm::Triple::x86:
+return "x86";
+  case llvm::Triple::x86_64:
+return "x64";
+  case llvm::Triple::arm:
+return "arm";
+  default:
+return "";
+  }
+}
+
 /// \brief Get Windows SDK installation directory.
 bool MSVCToolChain::getWindowsSDKDir(std::string , int ,
  int ) const {
@@ -263,26 +278,75 @@
 if (!found)
   return false;
 
-llvm::sys::path::append(libPath, "um");
-switch (getArch()) {
-case llvm::Triple::x86:
-  llvm::sys::path::append(libPath, "x86");
-  break;
-case llvm::Triple::x86_64:
-  llvm::sys::path::append(libPath, "x64");
-  break;
-case llvm::Triple::arm:
-  llvm::sys::path::append(libPath, "arm");
-  break;
-default:
+const StringRef archName = getWindowsSDKArch(getArch());
+if (archName.empty())
   return false;
-}
+llvm::sys::path::append(libPath, "um", archName);
   }
 
   path = libPath.str();
   return true;
 }
 
+// Check if the Include path of a specified version of Visual Studio contains
+// specific header files. If not, they are probably shipped with Universal CRT.
+bool clang::driver::toolchains::MSVCToolChain::useUniversalCRT(
+std::string ) const {
+  llvm::SmallString<128> TestPath(VisualStudioDir);
+  llvm::sys::path::append(TestPath, "VC\\include\\stdlib.h");
+
+  return !llvm::sys::fs::exists(TestPath);
+}
+
+bool MSVCToolChain::getUniversalCRTSdkDir(std::string ,
+  std::string ) const {
+  // vcvarsqueryregistry.bat for Visual Studio 2015 queries the registry
+  // for the specific key "KitsRoot10". So do we.
+  if (!getSystemRegistryString(
+  "SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots", "KitsRoot10",
+  Path, nullptr))
+return false;
+
+  UCRTVersion.clear();
+
+  // Find the most recent version of Universal CRT.
+  // vcvarsqueryregistry.bat sorts entries in the include directory by names and
+  // uses the last one of the list.
+  // So we compare entry names lexicographically to find the greatest one.
+  std::error_code EC;
+  llvm::SmallString<128> IncludePath(Path);
+  llvm::sys::path::append(IncludePath, "Include");
+  for (llvm::sys::fs::directory_iterator DirIt(IncludePath, EC), DirEnd;
+   DirIt != DirEnd && !EC; DirIt.increment(EC)) {
+if (!llvm::sys::fs::is_directory(DirIt->path()))
+  continue;
+StringRef CandidateName = llvm::sys::path::filename(DirIt->path());
+if (CandidateName > UCRTVersion)
+  UCRTVersion = CandidateName;
+  }
+
+  return !UCRTVersion.empty();
+}
+
+bool MSVCToolChain::getUniversalCRTLibraryPath(std::string ) const {
+  std::string UniversalCRTSdkPath;
+  std::string UCRTVersion;
+
+  Path.clear();
+  if (!getUniversalCRTSdkDir(UniversalCRTSdkPath, UCRTVersion))
+return false;
+
+  StringRef ArchName = getWindowsSDKArch(getArch());
+  if (ArchName.empty())
+