@@ -1888,16 +1888,23 @@ struct DarwinPlatform {
18881888 case TargetArg:
18891889 case MTargetOSArg:
18901890 case OSVersionArg:
1891- case InferredFromSDK:
1892- case InferredFromArch:
18931891 assert (Arg && " OS version argument not yet inferred" );
18941892 return Arg->getAsString (Args);
18951893 case DeploymentTargetEnv:
18961894 return (llvm::Twine (EnvVarName) + " =" + OSVersionStr).str ();
1895+ case InferredFromSDK:
1896+ case InferredFromArch:
1897+ llvm_unreachable (" Cannot print arguments for inferred OS version" );
18971898 }
18981899 llvm_unreachable (" Unsupported Darwin Source Kind" );
18991900 }
19001901
1902+ // Returns the inferred source of how the OS version was resolved.
1903+ std::string getInferredSource () {
1904+ assert (!isExplicitlySpecified () && " OS version was not inferred" );
1905+ return InferredSource.str ();
1906+ }
1907+
19011908 void setEnvironment (llvm::Triple::EnvironmentType EnvType,
19021909 const VersionTuple &OSVersion,
19031910 const std::optional<DarwinSDKInfo> &SDKInfo) {
@@ -1971,19 +1978,24 @@ struct DarwinPlatform {
19711978 Result.EnvVarName = EnvVarName;
19721979 return Result;
19731980 }
1974- static DarwinPlatform createFromSDK (DarwinPlatformKind Platform,
1981+ static DarwinPlatform createFromSDK (StringRef SDKRoot,
1982+ DarwinPlatformKind Platform,
19751983 StringRef Value,
19761984 bool IsSimulator = false ) {
19771985 DarwinPlatform Result (InferredFromSDK, Platform,
19781986 getVersionFromString (Value));
19791987 if (IsSimulator)
19801988 Result.Environment = DarwinEnvironmentKind::Simulator;
19811989 Result.InferSimulatorFromArch = false ;
1990+ Result.InferredSource = SDKRoot;
19821991 return Result;
19831992 }
1984- static DarwinPlatform createFromArch (llvm::Triple::OSType OS,
1993+ static DarwinPlatform createFromArch (StringRef Arch, llvm::Triple::OSType OS,
19851994 VersionTuple Version) {
1986- return DarwinPlatform (InferredFromArch, getPlatformFromOS (OS), Version);
1995+ auto Result =
1996+ DarwinPlatform (InferredFromArch, getPlatformFromOS (OS), Version);
1997+ Result.InferredSource = Arch;
1998+ return Result;
19871999 }
19882000
19892001 // / Constructs an inferred SDKInfo value based on the version inferred from
@@ -2069,6 +2081,9 @@ struct DarwinPlatform {
20692081 bool InferSimulatorFromArch = true ;
20702082 std::pair<Arg *, std::string> Arguments;
20712083 StringRef EnvVarName;
2084+ // If the DarwinPlatform information is derived from an inferred source, this
2085+ // captures what that source input was for error reporting.
2086+ StringRef InferredSource;
20722087 // When compiling for a zippered target, this value represents the target
20732088 // triple encoded in the target variant.
20742089 std::optional<llvm::Triple> TargetVariantTriple;
@@ -2237,26 +2252,27 @@ inferDeploymentTargetFromSDK(DerivedArgList &Args,
22372252 [&](StringRef SDK) -> std::optional<DarwinPlatform> {
22382253 if (SDK.starts_with (" iPhoneOS" ) || SDK.starts_with (" iPhoneSimulator" ))
22392254 return DarwinPlatform::createFromSDK (
2240- Darwin::IPhoneOS, Version,
2255+ isysroot, Darwin::IPhoneOS, Version,
22412256 /* IsSimulator=*/ SDK.starts_with (" iPhoneSimulator" ));
22422257 else if (SDK.starts_with (" MacOSX" ))
2243- return DarwinPlatform::createFromSDK (Darwin::MacOS,
2258+ return DarwinPlatform::createFromSDK (isysroot, Darwin::MacOS,
22442259 getSystemOrSDKMacOSVersion (Version));
22452260 else if (SDK.starts_with (" WatchOS" ) || SDK.starts_with (" WatchSimulator" ))
22462261 return DarwinPlatform::createFromSDK (
2247- Darwin::WatchOS, Version,
2262+ isysroot, Darwin::WatchOS, Version,
22482263 /* IsSimulator=*/ SDK.starts_with (" WatchSimulator" ));
22492264 else if (SDK.starts_with (" AppleTVOS" ) ||
22502265 SDK.starts_with (" AppleTVSimulator" ))
22512266 return DarwinPlatform::createFromSDK (
2252- Darwin::TvOS, Version,
2267+ isysroot, Darwin::TvOS, Version,
22532268 /* IsSimulator=*/ SDK.starts_with (" AppleTVSimulator" ));
22542269 else if (SDK.starts_with (" XR" ))
22552270 return DarwinPlatform::createFromSDK (
2256- Darwin::XROS, Version,
2271+ isysroot, Darwin::XROS, Version,
22572272 /* IsSimulator=*/ SDK.contains (" Simulator" ));
22582273 else if (SDK.starts_with (" DriverKit" ))
2259- return DarwinPlatform::createFromSDK (Darwin::DriverKit, Version);
2274+ return DarwinPlatform::createFromSDK (isysroot, Darwin::DriverKit,
2275+ Version);
22602276 return std::nullopt ;
22612277 };
22622278 if (auto Result = CreatePlatformFromSDKName (SDK))
@@ -2329,7 +2345,7 @@ inferDeploymentTargetFromArch(DerivedArgList &Args, const Darwin &Toolchain,
23292345 if (OSTy == llvm::Triple::UnknownOS)
23302346 return std::nullopt ;
23312347 return DarwinPlatform::createFromArch (
2332- OSTy, getInferredOSVersion (OSTy, Triple, TheDriver));
2348+ MachOArchName, OSTy, getInferredOSVersion (OSTy, Triple, TheDriver));
23332349}
23342350
23352351// / Returns the deployment target that's specified using the -target option.
@@ -2548,9 +2564,15 @@ void Darwin::AddDeploymentTarget(DerivedArgList &Args) const {
25482564 }
25492565
25502566 assert (PlatformAndVersion && " Unable to infer Darwin variant" );
2551- if (!PlatformAndVersion->isValidOSVersion ())
2552- getDriver ().Diag (diag::err_drv_invalid_version_number)
2553- << PlatformAndVersion->getAsString (Args, Opts);
2567+ if (!PlatformAndVersion->isValidOSVersion ()) {
2568+ if (PlatformAndVersion->isExplicitlySpecified ())
2569+ getDriver ().Diag (diag::err_drv_invalid_version_number)
2570+ << PlatformAndVersion->getAsString (Args, Opts);
2571+ else
2572+ getDriver ().Diag (diag::err_drv_invalid_version_number_inferred)
2573+ << PlatformAndVersion->getOSVersion ().getAsString ()
2574+ << PlatformAndVersion->getInferredSource ();
2575+ }
25542576 // After the deployment OS version has been resolved, set it to the canonical
25552577 // version before further error detection and converting to a proper target
25562578 // triple.
0 commit comments