diff options
| -rw-r--r-- | clang/lib/Driver/ToolChains.cpp | 31 | ||||
| -rw-r--r-- | clang/lib/Driver/ToolChains.h | 6 |
2 files changed, 21 insertions, 16 deletions
diff --git a/clang/lib/Driver/ToolChains.cpp b/clang/lib/Driver/ToolChains.cpp index 56f3e320faf..21fb2a60a25 100644 --- a/clang/lib/Driver/ToolChains.cpp +++ b/clang/lib/Driver/ToolChains.cpp @@ -943,31 +943,33 @@ Generic_GCC::GCCVersion Linux::GCCVersion::Parse(StringRef VersionText) { } /// \brief Less-than for GCCVersion, implementing a Strict Weak Ordering. -bool Generic_GCC::GCCVersion::operator<(const GCCVersion &RHS) const { - if (Major != RHS.Major) - return Major < RHS.Major; - if (Minor != RHS.Minor) - return Minor < RHS.Minor; - if (Patch != RHS.Patch) { +bool Generic_GCC::GCCVersion::isOlderThan(int RHSMajor, int RHSMinor, + int RHSPatch, + StringRef RHSPatchSuffix) const { + if (Major != RHSMajor) + return Major < RHSMajor; + if (Minor != RHSMinor) + return Minor < RHSMinor; + if (Patch != RHSPatch) { // Note that versions without a specified patch sort higher than those with // a patch. - if (RHS.Patch == -1) + if (RHSPatch == -1) return true; if (Patch == -1) return false; // Otherwise just sort on the patch itself. - return Patch < RHS.Patch; + return Patch < RHSPatch; } - if (PatchSuffix != RHS.PatchSuffix) { + if (PatchSuffix != RHSPatchSuffix) { // Sort empty suffixes higher. - if (RHS.PatchSuffix.empty()) + if (RHSPatchSuffix.empty()) return true; if (PatchSuffix.empty()) return false; // Provide a lexicographic sort to make this a total ordering. - return PatchSuffix < RHS.PatchSuffix; + return PatchSuffix < RHSPatchSuffix; } // The versions are equal. @@ -1396,8 +1398,7 @@ void Generic_GCC::GCCInstallationDetector::ScanLibDirForGCCTriple( CandidateGCCInstallPaths.push_back(LI->path()); StringRef VersionText = llvm::sys::path::filename(LI->path()); GCCVersion CandidateVersion = GCCVersion::Parse(VersionText); - static const GCCVersion MinVersion = { "4.1.1", 4, 1, 1, "" }; - if (CandidateVersion < MinVersion) + if (CandidateVersion.isOlderThan(4, 1, 1)) continue; if (CandidateVersion <= Version) continue; @@ -2372,8 +2373,8 @@ Tool *Linux::buildAssembler() const { void Linux::addClangTargetOptions(const ArgList &DriverArgs, ArgStringList &CC1Args) const { const Generic_GCC::GCCVersion &V = GCCInstallation.getVersion(); - bool UseInitArrayDefault - = V >= Generic_GCC::GCCVersion::Parse("4.7.0") || + bool UseInitArrayDefault = + !V.isOlderThan(4, 7, 0) || getTriple().getArch() == llvm::Triple::aarch64 || getTriple().getEnvironment() == llvm::Triple::Android; if (DriverArgs.hasFlag(options::OPT_fuse_init_array, diff --git a/clang/lib/Driver/ToolChains.h b/clang/lib/Driver/ToolChains.h index 02ac4f513b9..395826ea5f7 100644 --- a/clang/lib/Driver/ToolChains.h +++ b/clang/lib/Driver/ToolChains.h @@ -54,7 +54,11 @@ protected: std::string PatchSuffix; static GCCVersion Parse(StringRef VersionText); - bool operator<(const GCCVersion &RHS) const; + bool isOlderThan(int RHSMajor, int RHSMinor, int RHSPatch, + StringRef RHSPatchSuffix = StringRef()) const; + bool operator<(const GCCVersion &RHS) const { + return isOlderThan(RHS.Major, RHS.Minor, RHS.Patch, RHS.PatchSuffix); + } bool operator>(const GCCVersion &RHS) const { return RHS < *this; } bool operator<=(const GCCVersion &RHS) const { return !(*this > RHS); } bool operator>=(const GCCVersion &RHS) const { return !(*this < RHS); } |

