diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp index 443c188cc20ec..1a02d3cfbac7c 100644 --- a/clang/lib/Driver/ToolChains/Darwin.cpp +++ b/clang/lib/Driver/ToolChains/Darwin.cpp @@ -1485,17 +1485,19 @@ void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args, /// If the macOS SDK version is the same or earlier than the system version, /// then the SDK version is returned. Otherwise the system version is returned. static std::string getSystemOrSDKMacOSVersion(StringRef MacOSSDKVersion) { - unsigned Major, Minor, Micro; llvm::Triple SystemTriple(llvm::sys::getProcessTriple()); if (!SystemTriple.isMacOSX()) return std::string(MacOSSDKVersion); VersionTuple SystemVersion; SystemTriple.getMacOSXVersion(SystemVersion); + + unsigned Major, Minor, Micro; bool HadExtra; if (!Driver::GetReleaseVersion(MacOSSDKVersion, Major, Minor, Micro, HadExtra)) return std::string(MacOSSDKVersion); VersionTuple SDKVersion(Major, Minor, Micro); + if (SDKVersion > SystemVersion) return SystemVersion.getAsString(); return std::string(MacOSSDKVersion);