r269515 - Get default -fms-compatibility-version from cl.exe's version
Adrian McCarthy via cfe-commits
cfe-commits at lists.llvm.org
Fri May 13 16:20:11 PDT 2016
Author: amccarth
Date: Fri May 13 18:20:11 2016
New Revision: 269515
URL: http://llvm.org/viewvc/llvm-project?rev=269515&view=rev
Log:
Get default -fms-compatibility-version from cl.exe's version
-fms-compatibility-version was defaulting to 18 (VS 2013), which is a pain if your environment is pointing to version 19 (VS 2015) libraries.
If cl.exe can be found, this patch uses its version number as the default instead. It re-uses the existing code to find the Visual Studio binaries folder and WinAPI methods to check its version. You can still explicitly specify a compatibility version on the command line. If you don't have cl.exe, this should be a no-op and you'll get the old default of 18.
This affected the tests, which assumed that if you didn't specific a version, that it would default to 18, but this won't be true for all machines. So a couple test cases had to be eliminated and a couple others had to be tweaked to allow for various outputs.
Addresses: https://llvm.org/bugs/show_bug.cgi?id=27215
Differential Revision: http://reviews.llvm.org/D20136
Modified:
cfe/trunk/include/clang/Driver/ToolChain.h
cfe/trunk/lib/Driver/MSVCToolChain.cpp
cfe/trunk/lib/Driver/ToolChains.h
cfe/trunk/lib/Driver/Tools.cpp
cfe/trunk/lib/Driver/Tools.h
cfe/trunk/test/Driver/cl-options.c
cfe/trunk/test/Driver/msc-version.c
cfe/trunk/test/Driver/msvc-triple.c
cfe/trunk/test/Misc/diag-format.c
Modified: cfe/trunk/include/clang/Driver/ToolChain.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/ToolChain.h?rev=269515&r1=269514&r2=269515&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/ToolChain.h (original)
+++ cfe/trunk/include/clang/Driver/ToolChain.h Fri May 13 18:20:11 2016
@@ -11,6 +11,7 @@
#define LLVM_CLANG_DRIVER_TOOLCHAIN_H
#include "clang/Basic/Sanitizers.h"
+#include "clang/Basic/VersionTuple.h"
#include "clang/Driver/Action.h"
#include "clang/Driver/Multilib.h"
#include "clang/Driver/Types.h"
@@ -422,6 +423,10 @@ public:
/// \brief Return sanitizers which are enabled by default.
virtual SanitizerMask getDefaultSanitizers() const { return 0; }
+
+ /// \brief On Windows, returns the version of cl.exe. On other platforms,
+ /// returns an empty VersionTuple.
+ virtual VersionTuple getMSVCVersionFromExe() const { return VersionTuple(); }
};
} // end namespace driver
Modified: cfe/trunk/lib/Driver/MSVCToolChain.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/MSVCToolChain.cpp?rev=269515&r1=269514&r2=269515&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/MSVCToolChain.cpp (original)
+++ cfe/trunk/lib/Driver/MSVCToolChain.cpp Fri May 13 18:20:11 2016
@@ -19,6 +19,7 @@
#include "llvm/Config/llvm-config.h"
#include "llvm/Option/Arg.h"
#include "llvm/Option/ArgList.h"
+#include "llvm/Support/ConvertUTF.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Process.h"
@@ -37,6 +38,8 @@
#define NOMINMAX
#endif
#include <windows.h>
+
+ #pragma comment(lib, "version.lib")
#endif
using namespace clang::driver;
@@ -457,6 +460,45 @@ bool MSVCToolChain::getVisualStudioBinar
return true;
}
+VersionTuple MSVCToolChain::getMSVCVersionFromExe() const {
+ VersionTuple Version;
+#ifdef USE_WIN32
+ std::string BinPath;
+ if (!getVisualStudioBinariesFolder("", BinPath))
+ return Version;
+ SmallString<128> ClExe = BinPath;
+ llvm::sys::path::append(ClExe, "cl.exe");
+
+ std::wstring ClExeWide;
+ if (!llvm::ConvertUTF8toWide(ClExe.c_str(), ClExeWide))
+ return Version;
+
+ const DWORD VersionSize = ::GetFileVersionInfoSizeW(ClExeWide.c_str(),
+ nullptr);
+ if (VersionSize == 0)
+ return Version;
+
+ SmallVector<uint8_t, 4 * 1024> VersionBlock(VersionSize);
+ if (!::GetFileVersionInfoW(ClExeWide.c_str(), 0, VersionSize,
+ VersionBlock.data()))
+ return Version;
+
+ VS_FIXEDFILEINFO *FileInfo = nullptr;
+ UINT FileInfoSize = 0;
+ if (!::VerQueryValueW(VersionBlock.data(), L"\\",
+ reinterpret_cast<LPVOID *>(&FileInfo), &FileInfoSize) ||
+ FileInfoSize < sizeof(*FileInfo))
+ return Version;
+
+ const unsigned Major = (FileInfo->dwFileVersionMS >> 16) & 0xFFFF;
+ const unsigned Minor = (FileInfo->dwFileVersionMS ) & 0xFFFF;
+ const unsigned Micro = (FileInfo->dwFileVersionLS >> 16) & 0xFFFF;
+
+ Version = VersionTuple(Major, Minor, Micro);
+#endif
+ return Version;
+}
+
// Get Visual Studio installation directory.
bool MSVCToolChain::getVisualStudioInstallDir(std::string &path) const {
// First check the environment variables that vsvars32.bat sets.
@@ -618,7 +660,7 @@ MSVCToolChain::ComputeEffectiveClangTrip
ToolChain::ComputeEffectiveClangTriple(Args, InputType);
llvm::Triple Triple(TripleStr);
VersionTuple MSVT =
- tools::visualstudio::getMSVCVersion(/*D=*/nullptr, Triple, Args,
+ tools::visualstudio::getMSVCVersion(/*D=*/nullptr, *this, Triple, Args,
/*IsWindowsMSVC=*/true);
if (MSVT.empty())
return TripleStr;
Modified: cfe/trunk/lib/Driver/ToolChains.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.h?rev=269515&r1=269514&r2=269515&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains.h (original)
+++ cfe/trunk/lib/Driver/ToolChains.h Fri May 13 18:20:11 2016
@@ -1028,6 +1028,7 @@ public:
bool getVisualStudioInstallDir(std::string &path) const;
bool getVisualStudioBinariesFolder(const char *clangProgramPath,
std::string &path) const;
+ VersionTuple getMSVCVersionFromExe() const override;
std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList &Args,
types::ID InputType) const override;
Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=269515&r1=269514&r2=269515&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Fri May 13 18:20:11 2016
@@ -3293,7 +3293,7 @@ static void appendUserToPath(SmallVector
Result.append(UID.begin(), UID.end());
}
-VersionTuple visualstudio::getMSVCVersion(const Driver *D,
+VersionTuple visualstudio::getMSVCVersion(const Driver *D, const ToolChain &TC,
const llvm::Triple &Triple,
const llvm::opt::ArgList &Args,
bool IsWindowsMSVC) {
@@ -3335,8 +3335,14 @@ VersionTuple visualstudio::getMSVCVersio
if (Major || Minor || Micro)
return VersionTuple(Major, Minor, Micro);
- // FIXME: Consider bumping this to 19 (MSVC2015) soon.
- return VersionTuple(18);
+ if (IsWindowsMSVC) {
+ VersionTuple MSVT = TC.getMSVCVersionFromExe();
+ if (!MSVT.empty())
+ return MSVT;
+
+ // FIXME: Consider bumping this to 19 (MSVC2015) soon.
+ return VersionTuple(18);
+ }
}
return VersionTuple();
}
@@ -5226,7 +5232,7 @@ void Clang::ConstructJob(Compilation &C,
// -fms-compatibility-version=18.00 is default.
VersionTuple MSVT = visualstudio::getMSVCVersion(
- &D, getToolChain().getTriple(), Args, IsWindowsMSVC);
+ &D, getToolChain(), getToolChain().getTriple(), Args, IsWindowsMSVC);
if (!MSVT.empty())
CmdArgs.push_back(
Args.MakeArgString("-fms-compatibility-version=" + MSVT.getAsString()));
Modified: cfe/trunk/lib/Driver/Tools.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.h?rev=269515&r1=269514&r2=269515&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Tools.h (original)
+++ cfe/trunk/lib/Driver/Tools.h Fri May 13 18:20:11 2016
@@ -682,7 +682,8 @@ public:
/// Visual studio tools.
namespace visualstudio {
-VersionTuple getMSVCVersion(const Driver *D, const llvm::Triple &Triple,
+VersionTuple getMSVCVersion(const Driver *D, const ToolChain &TC,
+ const llvm::Triple &Triple,
const llvm::opt::ArgList &Args, bool IsWindowsMSVC);
class LLVM_LIBRARY_VISIBILITY Linker : public Tool {
Modified: cfe/trunk/test/Driver/cl-options.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/cl-options.c?rev=269515&r1=269514&r2=269515&view=diff
==============================================================================
--- cfe/trunk/test/Driver/cl-options.c (original)
+++ cfe/trunk/test/Driver/cl-options.c Fri May 13 18:20:11 2016
@@ -387,7 +387,7 @@
// RTTI-NOT: "-fno-rtti"
// thread safe statics are off for versions < 19.
-// RUN: %clang_cl /c -### -- %s 2>&1 | FileCheck -check-prefix=NoThreadSafeStatics %s
+// RUN: %clang_cl /c -### -fms-compatibility-version=18 -- %s 2>&1 | FileCheck -check-prefix=NoThreadSafeStatics %s
// RUN: %clang_cl /Zc:threadSafeInit /Zc:threadSafeInit- /c -### -- %s 2>&1 | FileCheck -check-prefix=NoThreadSafeStatics %s
// NoThreadSafeStatics: "-fno-threadsafe-statics"
Modified: cfe/trunk/test/Driver/msc-version.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/msc-version.c?rev=269515&r1=269514&r2=269515&view=diff
==============================================================================
--- cfe/trunk/test/Driver/msc-version.c (original)
+++ cfe/trunk/test/Driver/msc-version.c Fri May 13 18:20:11 2016
@@ -1,15 +1,4 @@
//
-// Verify defaults
-//
-
-// RUN: %clang -target i686-windows -fms-compatibility -dM -E - </dev/null -o - | FileCheck %s -check-prefix CHECK-NO-MSC-VERSION
-
-// CHECK-NO-MSC-VERSION: _MSC_BUILD 1
-// CHECK-NO-MSC-VERSION: _MSC_FULL_VER 180000000
-// CHECK-NO-MSC-VERSION: _MSC_VER 1800
-
-
-//
// Verify -fms-compatibility-version parsing
//
Modified: cfe/trunk/test/Driver/msvc-triple.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/msvc-triple.c?rev=269515&r1=269514&r2=269515&view=diff
==============================================================================
--- cfe/trunk/test/Driver/msvc-triple.c (original)
+++ cfe/trunk/test/Driver/msvc-triple.c Fri May 13 18:20:11 2016
@@ -1,9 +1,7 @@
-// RUN: %clang -target i686-pc-windows-msvc -S -emit-llvm %s -o - | FileCheck %s --check-prefix=DEFAULT
// RUN: %clang -target i686-pc-windows-msvc19 -S -emit-llvm %s -o - | FileCheck %s --check-prefix=TARGET-19
// RUN: %clang -target i686-pc-windows-msvc -S -emit-llvm %s -o - -fms-compatibility-version=19 | FileCheck %s --check-prefix=OVERRIDE-19
// RUN: %clang -target i686-pc-windows-msvc-elf -S -emit-llvm %s -o - | FileCheck %s --check-prefix=ELF-DEFAULT
-// DEFAULT: target triple = "i686-pc-windows-msvc18.0.0"
// TARGET-19: target triple = "i686-pc-windows-msvc19.0.0"
// OVERRIDE-19: target triple = "i686-pc-windows-msvc19.0.0"
-// ELF-DEFAULT: target triple = "i686-pc-windows-msvc18.0.0-elf"
+// ELF-DEFAULT: target triple = "i686-pc-windows-msvc{{.*}}-elf"
Modified: cfe/trunk/test/Misc/diag-format.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Misc/diag-format.c?rev=269515&r1=269514&r2=269515&view=diff
==============================================================================
--- cfe/trunk/test/Misc/diag-format.c (original)
+++ cfe/trunk/test/Misc/diag-format.c Fri May 13 18:20:11 2016
@@ -37,7 +37,7 @@
// DEFAULT: {{.*}}:36:8: warning: extra tokens at end of #endif directive [-Wextra-tokens]
// MSVC2010: {{.*}}(36,7) : warning: extra tokens at end of #endif directive [-Wextra-tokens]
// MSVC2013: {{.*}}(36,8) : warning: extra tokens at end of #endif directive [-Wextra-tokens]
-// MSVC: {{.*}}(36,8) : warning: extra tokens at end of #endif directive [-Wextra-tokens]
+// MSVC: {{.*}}(36,8){{ ?}}: warning: extra tokens at end of #endif directive [-Wextra-tokens]
// MSVC2015: {{.*}}(36,8): warning: extra tokens at end of #endif directive [-Wextra-tokens]
// VI: {{.*}} +36:8: warning: extra tokens at end of #endif directive [-Wextra-tokens]
// MSVC2015_ORIG: {{.*}}(36): warning: extra tokens at end of #endif directive [-Wextra-tokens]
More information about the cfe-commits
mailing list