diff options
author | David L. Jones <dlj@google.com> | 2016-12-07 23:41:58 +0000 |
---|---|---|
committer | David L. Jones <dlj@google.com> | 2016-12-07 23:41:58 +0000 |
commit | 24fb20c13d2e3a7eb6a787dec1c16639d873452f (patch) | |
tree | 1a86c663f7cc81fc11ee4143694fbbd2f646b4a0 /clang/lib/Driver/Tools.cpp | |
parent | 62cd86863ac8ea13948a0397f46eead6a18d60b0 (diff) | |
download | llvm-24fb20c13d2e3a7eb6a787dec1c16639d873452f.zip llvm-24fb20c13d2e3a7eb6a787dec1c16639d873452f.tar.gz llvm-24fb20c13d2e3a7eb6a787dec1c16639d873452f.tar.bz2 |
Refactor how the MSVC toolchain searches for a compatibility version.
Summary:
The MSVC toolchain and Clang driver combination currently uses a fairly complex
sequence of steps to determine the MS compatibility version to pass to cc1.
There is some oddness in this sequence currently, with some code which inspects
flags in the toolchain, and some code which inspects the triple and local
environment in the driver code.
This change is an attempt to consolidate most of this logic so that
Win32-specific code lives in MSVCToolChain.cpp. I'm not 100% happy with the
split, so any suggestions are welcome.
There are a few things you might want to watch for for specifically:
- On all platforms, if MSVC compatibility flags are provided (and valid), use
those.
- The fallback sequence should be the same as before, but is now consolidated
into MSVCToolChain::getMSVCVersion:
- Otherwise, try to use the Triple.
- Otherwise, on Windows, check the executable.
- Otherwise, on Windows or with --fms-extensions, default to 18.
- Otherwise, we can't determine the version.
- MSVCToolChain::ComputeEffectiveTriple no longer calls the base
ToolChain::ComputeEffectiveClangTriple. The only thing it would change for
Windows the architecture, which we don't care about for the compatibility
version.
- I'm not sure whether this is philosophically correct (but it should
be easy to add back to MSVCToolChain::getMSVCVersionFromTriple if not).
- Previously, Tools.cpp just called getTriple() anyhow, so it doesn't look
like the effective triple was always being used previously anyhow.
Reviewers: hans, compnerd, llvm-commits, rnk
Subscribers: amccarth
Differential Revision: https://reviews.llvm.org/D27477
llvm-svn: 288998
Diffstat (limited to 'clang/lib/Driver/Tools.cpp')
-rw-r--r-- | clang/lib/Driver/Tools.cpp | 72 |
1 files changed, 2 insertions, 70 deletions
diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp index 8a38fc8..ae38723 100644 --- a/clang/lib/Driver/Tools.cpp +++ b/clang/lib/Driver/Tools.cpp @@ -3552,19 +3552,6 @@ static void addDashXForInput(const ArgList &Args, const InputInfo &Input, CmdArgs.push_back(types::getTypeName(Input.getType())); } -static VersionTuple getMSCompatibilityVersion(unsigned Version) { - if (Version < 100) - return VersionTuple(Version); - - if (Version < 10000) - return VersionTuple(Version / 100, Version % 100); - - unsigned Build = 0, Factor = 1; - for (; Version > 10000; Version = Version / 10, Factor = Factor * 10) - Build = Build + (Version % 10) * Factor; - return VersionTuple(Version / 100, Version % 100, Build); -} - // Claim options we don't want to warn if they are unused. We do this for // options that build systems might add but are unused when assembling or only // running the preprocessor for example. @@ -3608,60 +3595,6 @@ static void appendUserToPath(SmallVectorImpl<char> &Result) { Result.append(UID.begin(), UID.end()); } -VersionTuple visualstudio::getMSVCVersion(const Driver *D, const ToolChain &TC, - const llvm::Triple &Triple, - const llvm::opt::ArgList &Args, - bool IsWindowsMSVC) { - if (Args.hasFlag(options::OPT_fms_extensions, options::OPT_fno_ms_extensions, - IsWindowsMSVC) || - Args.hasArg(options::OPT_fmsc_version) || - Args.hasArg(options::OPT_fms_compatibility_version)) { - const Arg *MSCVersion = Args.getLastArg(options::OPT_fmsc_version); - const Arg *MSCompatibilityVersion = - Args.getLastArg(options::OPT_fms_compatibility_version); - - if (MSCVersion && MSCompatibilityVersion) { - if (D) - D->Diag(diag::err_drv_argument_not_allowed_with) - << MSCVersion->getAsString(Args) - << MSCompatibilityVersion->getAsString(Args); - return VersionTuple(); - } - - if (MSCompatibilityVersion) { - VersionTuple MSVT; - if (MSVT.tryParse(MSCompatibilityVersion->getValue()) && D) - D->Diag(diag::err_drv_invalid_value) - << MSCompatibilityVersion->getAsString(Args) - << MSCompatibilityVersion->getValue(); - return MSVT; - } - - if (MSCVersion) { - unsigned Version = 0; - if (StringRef(MSCVersion->getValue()).getAsInteger(10, Version) && D) - D->Diag(diag::err_drv_invalid_value) << MSCVersion->getAsString(Args) - << MSCVersion->getValue(); - return getMSCompatibilityVersion(Version); - } - - unsigned Major, Minor, Micro; - Triple.getEnvironmentVersion(Major, Minor, Micro); - if (Major || Minor || Micro) - return VersionTuple(Major, Minor, Micro); - - if (IsWindowsMSVC) { - VersionTuple MSVT = TC.getMSVCVersionFromExe(); - if (!MSVT.empty()) - return MSVT; - - // FIXME: Consider bumping this to 19 (MSVC2015) soon. - return VersionTuple(18); - } - } - return VersionTuple(); -} - static Arg *getLastProfileUseArg(const ArgList &Args) { auto *ProfileUseArg = Args.getLastArg( options::OPT_fprofile_instr_use, options::OPT_fprofile_instr_use_EQ, @@ -5867,9 +5800,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, options::OPT_fno_ms_extensions, true)))) CmdArgs.push_back("-fms-compatibility"); - // -fms-compatibility-version=18.00 is default. - VersionTuple MSVT = visualstudio::getMSVCVersion( - &D, getToolChain(), getToolChain().getTriple(), Args, IsWindowsMSVC); + VersionTuple MSVT = + getToolChain().computeMSVCVersion(&getToolChain().getDriver(), Args); if (!MSVT.empty()) CmdArgs.push_back( Args.MakeArgString("-fms-compatibility-version=" + MSVT.getAsString())); |