forked from OSchip/llvm-project
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 llvm-svn: 269515
This commit is contained in:
parent
3e42b22e59
commit
e4b26fc7a7
|
@ -11,6 +11,7 @@
|
||||||
#define LLVM_CLANG_DRIVER_TOOLCHAIN_H
|
#define LLVM_CLANG_DRIVER_TOOLCHAIN_H
|
||||||
|
|
||||||
#include "clang/Basic/Sanitizers.h"
|
#include "clang/Basic/Sanitizers.h"
|
||||||
|
#include "clang/Basic/VersionTuple.h"
|
||||||
#include "clang/Driver/Action.h"
|
#include "clang/Driver/Action.h"
|
||||||
#include "clang/Driver/Multilib.h"
|
#include "clang/Driver/Multilib.h"
|
||||||
#include "clang/Driver/Types.h"
|
#include "clang/Driver/Types.h"
|
||||||
|
@ -422,6 +423,10 @@ public:
|
||||||
|
|
||||||
/// \brief Return sanitizers which are enabled by default.
|
/// \brief Return sanitizers which are enabled by default.
|
||||||
virtual SanitizerMask getDefaultSanitizers() const { return 0; }
|
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
|
} // end namespace driver
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include "llvm/Config/llvm-config.h"
|
#include "llvm/Config/llvm-config.h"
|
||||||
#include "llvm/Option/Arg.h"
|
#include "llvm/Option/Arg.h"
|
||||||
#include "llvm/Option/ArgList.h"
|
#include "llvm/Option/ArgList.h"
|
||||||
|
#include "llvm/Support/ConvertUTF.h"
|
||||||
#include "llvm/Support/ErrorHandling.h"
|
#include "llvm/Support/ErrorHandling.h"
|
||||||
#include "llvm/Support/FileSystem.h"
|
#include "llvm/Support/FileSystem.h"
|
||||||
#include "llvm/Support/Process.h"
|
#include "llvm/Support/Process.h"
|
||||||
|
@ -37,6 +38,8 @@
|
||||||
#define NOMINMAX
|
#define NOMINMAX
|
||||||
#endif
|
#endif
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
|
#pragma comment(lib, "version.lib")
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
using namespace clang::driver;
|
using namespace clang::driver;
|
||||||
|
@ -457,6 +460,45 @@ bool MSVCToolChain::getVisualStudioBinariesFolder(const char *clangProgramPath,
|
||||||
return true;
|
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.
|
// Get Visual Studio installation directory.
|
||||||
bool MSVCToolChain::getVisualStudioInstallDir(std::string &path) const {
|
bool MSVCToolChain::getVisualStudioInstallDir(std::string &path) const {
|
||||||
// First check the environment variables that vsvars32.bat sets.
|
// First check the environment variables that vsvars32.bat sets.
|
||||||
|
@ -618,7 +660,7 @@ MSVCToolChain::ComputeEffectiveClangTriple(const ArgList &Args,
|
||||||
ToolChain::ComputeEffectiveClangTriple(Args, InputType);
|
ToolChain::ComputeEffectiveClangTriple(Args, InputType);
|
||||||
llvm::Triple Triple(TripleStr);
|
llvm::Triple Triple(TripleStr);
|
||||||
VersionTuple MSVT =
|
VersionTuple MSVT =
|
||||||
tools::visualstudio::getMSVCVersion(/*D=*/nullptr, Triple, Args,
|
tools::visualstudio::getMSVCVersion(/*D=*/nullptr, *this, Triple, Args,
|
||||||
/*IsWindowsMSVC=*/true);
|
/*IsWindowsMSVC=*/true);
|
||||||
if (MSVT.empty())
|
if (MSVT.empty())
|
||||||
return TripleStr;
|
return TripleStr;
|
||||||
|
|
|
@ -1028,6 +1028,7 @@ public:
|
||||||
bool getVisualStudioInstallDir(std::string &path) const;
|
bool getVisualStudioInstallDir(std::string &path) const;
|
||||||
bool getVisualStudioBinariesFolder(const char *clangProgramPath,
|
bool getVisualStudioBinariesFolder(const char *clangProgramPath,
|
||||||
std::string &path) const;
|
std::string &path) const;
|
||||||
|
VersionTuple getMSVCVersionFromExe() const override;
|
||||||
|
|
||||||
std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList &Args,
|
std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList &Args,
|
||||||
types::ID InputType) const override;
|
types::ID InputType) const override;
|
||||||
|
|
|
@ -3293,7 +3293,7 @@ static void appendUserToPath(SmallVectorImpl<char> &Result) {
|
||||||
Result.append(UID.begin(), UID.end());
|
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::Triple &Triple,
|
||||||
const llvm::opt::ArgList &Args,
|
const llvm::opt::ArgList &Args,
|
||||||
bool IsWindowsMSVC) {
|
bool IsWindowsMSVC) {
|
||||||
|
@ -3335,8 +3335,14 @@ VersionTuple visualstudio::getMSVCVersion(const Driver *D,
|
||||||
if (Major || Minor || Micro)
|
if (Major || Minor || Micro)
|
||||||
return VersionTuple(Major, Minor, Micro);
|
return VersionTuple(Major, Minor, Micro);
|
||||||
|
|
||||||
// FIXME: Consider bumping this to 19 (MSVC2015) soon.
|
if (IsWindowsMSVC) {
|
||||||
return VersionTuple(18);
|
VersionTuple MSVT = TC.getMSVCVersionFromExe();
|
||||||
|
if (!MSVT.empty())
|
||||||
|
return MSVT;
|
||||||
|
|
||||||
|
// FIXME: Consider bumping this to 19 (MSVC2015) soon.
|
||||||
|
return VersionTuple(18);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return VersionTuple();
|
return VersionTuple();
|
||||||
}
|
}
|
||||||
|
@ -5226,7 +5232,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
|
||||||
|
|
||||||
// -fms-compatibility-version=18.00 is default.
|
// -fms-compatibility-version=18.00 is default.
|
||||||
VersionTuple MSVT = visualstudio::getMSVCVersion(
|
VersionTuple MSVT = visualstudio::getMSVCVersion(
|
||||||
&D, getToolChain().getTriple(), Args, IsWindowsMSVC);
|
&D, getToolChain(), getToolChain().getTriple(), Args, IsWindowsMSVC);
|
||||||
if (!MSVT.empty())
|
if (!MSVT.empty())
|
||||||
CmdArgs.push_back(
|
CmdArgs.push_back(
|
||||||
Args.MakeArgString("-fms-compatibility-version=" + MSVT.getAsString()));
|
Args.MakeArgString("-fms-compatibility-version=" + MSVT.getAsString()));
|
||||||
|
|
|
@ -682,7 +682,8 @@ public:
|
||||||
|
|
||||||
/// Visual studio tools.
|
/// Visual studio tools.
|
||||||
namespace visualstudio {
|
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);
|
const llvm::opt::ArgList &Args, bool IsWindowsMSVC);
|
||||||
|
|
||||||
class LLVM_LIBRARY_VISIBILITY Linker : public Tool {
|
class LLVM_LIBRARY_VISIBILITY Linker : public Tool {
|
||||||
|
|
|
@ -387,7 +387,7 @@
|
||||||
// RTTI-NOT: "-fno-rtti"
|
// RTTI-NOT: "-fno-rtti"
|
||||||
|
|
||||||
// thread safe statics are off for versions < 19.
|
// 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
|
// RUN: %clang_cl /Zc:threadSafeInit /Zc:threadSafeInit- /c -### -- %s 2>&1 | FileCheck -check-prefix=NoThreadSafeStatics %s
|
||||||
// NoThreadSafeStatics: "-fno-threadsafe-statics"
|
// NoThreadSafeStatics: "-fno-threadsafe-statics"
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,3 @@
|
||||||
//
|
|
||||||
// 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
|
// Verify -fms-compatibility-version parsing
|
||||||
//
|
//
|
||||||
|
|
|
@ -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-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 -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
|
// 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"
|
// TARGET-19: target triple = "i686-pc-windows-msvc19.0.0"
|
||||||
// OVERRIDE-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"
|
||||||
|
|
|
@ -37,7 +37,7 @@
|
||||||
// DEFAULT: {{.*}}:36:8: warning: extra tokens at end of #endif directive [-Wextra-tokens]
|
// 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]
|
// 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]
|
// 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]
|
// 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]
|
// 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]
|
// MSVC2015_ORIG: {{.*}}(36): warning: extra tokens at end of #endif directive [-Wextra-tokens]
|
||||||
|
|
Loading…
Reference in New Issue