From: Benjamin Kramer Date: Fri, 9 Aug 2013 17:17:48 +0000 (+0000) Subject: Add a convenient way to compare GCCVersions without creating temporary objects. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ed5f28fd8bdb0ea39a28f4ade6b3ab57f0c8f780;p=clang Add a convenient way to compare GCCVersions without creating temporary objects. No functionality change. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@188084 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Driver/ToolChains.cpp b/lib/Driver/ToolChains.cpp index 56f3e320fa..21fb2a60a2 100644 --- a/lib/Driver/ToolChains.cpp +++ b/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/lib/Driver/ToolChains.h b/lib/Driver/ToolChains.h index 02ac4f513b..395826ea5f 100644 --- a/lib/Driver/ToolChains.h +++ b/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); }