@@ -1793,16 +1793,23 @@ struct DarwinPlatform {
1793
1793
case TargetArg:
1794
1794
case MTargetOSArg:
1795
1795
case OSVersionArg:
1796
- case InferredFromSDK:
1797
- case InferredFromArch:
1798
1796
assert (Arg && " OS version argument not yet inferred" );
1799
1797
return Arg->getAsString (Args);
1800
1798
case DeploymentTargetEnv:
1801
1799
return (llvm::Twine (EnvVarName) + " =" + OSVersionStr).str ();
1800
+ case InferredFromSDK:
1801
+ case InferredFromArch:
1802
+ llvm_unreachable (" Cannot print arguments for inferred OS version" );
1802
1803
}
1803
1804
llvm_unreachable (" Unsupported Darwin Source Kind" );
1804
1805
}
1805
1806
1807
+ // Returns the inferred source of how the OS version was resolved.
1808
+ std::string getInferredSource () {
1809
+ assert (!isExplicitlySpecified () && " OS version was not inferred" );
1810
+ return InferredSource.str ();
1811
+ }
1812
+
1806
1813
void setEnvironment (llvm::Triple::EnvironmentType EnvType,
1807
1814
const VersionTuple &OSVersion,
1808
1815
const std::optional<DarwinSDKInfo> &SDKInfo) {
@@ -1876,19 +1883,24 @@ struct DarwinPlatform {
1876
1883
Result.EnvVarName = EnvVarName;
1877
1884
return Result;
1878
1885
}
1879
- static DarwinPlatform createFromSDK (DarwinPlatformKind Platform,
1886
+ static DarwinPlatform createFromSDK (StringRef SDKRoot,
1887
+ DarwinPlatformKind Platform,
1880
1888
StringRef Value,
1881
1889
bool IsSimulator = false ) {
1882
1890
DarwinPlatform Result (InferredFromSDK, Platform,
1883
1891
getVersionFromString (Value));
1884
1892
if (IsSimulator)
1885
1893
Result.Environment = DarwinEnvironmentKind::Simulator;
1886
1894
Result.InferSimulatorFromArch = false ;
1895
+ Result.InferredSource = SDKRoot;
1887
1896
return Result;
1888
1897
}
1889
- static DarwinPlatform createFromArch (llvm::Triple::OSType OS,
1898
+ static DarwinPlatform createFromArch (StringRef Arch, llvm::Triple::OSType OS,
1890
1899
VersionTuple Version) {
1891
- return DarwinPlatform (InferredFromArch, getPlatformFromOS (OS), Version);
1900
+ auto Result =
1901
+ DarwinPlatform (InferredFromArch, getPlatformFromOS (OS), Version);
1902
+ Result.InferredSource = Arch;
1903
+ return Result;
1892
1904
}
1893
1905
1894
1906
// / Constructs an inferred SDKInfo value based on the version inferred from
@@ -1975,6 +1987,9 @@ struct DarwinPlatform {
1975
1987
bool InferSimulatorFromArch = true ;
1976
1988
std::pair<Arg *, std::string> Arguments;
1977
1989
StringRef EnvVarName;
1990
+ // If the DarwinPlatform information is derived from an inferred source, this
1991
+ // captures what that source input was for error reporting.
1992
+ StringRef InferredSource;
1978
1993
// When compiling for a zippered target, this value represents the target
1979
1994
// triple encoded in the target variant.
1980
1995
std::optional<llvm::Triple> TargetVariantTriple;
@@ -2143,26 +2158,27 @@ inferDeploymentTargetFromSDK(DerivedArgList &Args,
2143
2158
[&](StringRef SDK) -> std::optional<DarwinPlatform> {
2144
2159
if (SDK.starts_with (" iPhoneOS" ) || SDK.starts_with (" iPhoneSimulator" ))
2145
2160
return DarwinPlatform::createFromSDK (
2146
- Darwin::IPhoneOS, Version,
2161
+ isysroot, Darwin::IPhoneOS, Version,
2147
2162
/* IsSimulator=*/ SDK.starts_with (" iPhoneSimulator" ));
2148
2163
else if (SDK.starts_with (" MacOSX" ))
2149
- return DarwinPlatform::createFromSDK (Darwin::MacOS,
2164
+ return DarwinPlatform::createFromSDK (isysroot, Darwin::MacOS,
2150
2165
getSystemOrSDKMacOSVersion (Version));
2151
2166
else if (SDK.starts_with (" WatchOS" ) || SDK.starts_with (" WatchSimulator" ))
2152
2167
return DarwinPlatform::createFromSDK (
2153
- Darwin::WatchOS, Version,
2168
+ isysroot, Darwin::WatchOS, Version,
2154
2169
/* IsSimulator=*/ SDK.starts_with (" WatchSimulator" ));
2155
2170
else if (SDK.starts_with (" AppleTVOS" ) ||
2156
2171
SDK.starts_with (" AppleTVSimulator" ))
2157
2172
return DarwinPlatform::createFromSDK (
2158
- Darwin::TvOS, Version,
2173
+ isysroot, Darwin::TvOS, Version,
2159
2174
/* IsSimulator=*/ SDK.starts_with (" AppleTVSimulator" ));
2160
2175
else if (SDK.starts_with (" XR" ))
2161
2176
return DarwinPlatform::createFromSDK (
2162
- Darwin::XROS, Version,
2177
+ isysroot, Darwin::XROS, Version,
2163
2178
/* IsSimulator=*/ SDK.contains (" Simulator" ));
2164
2179
else if (SDK.starts_with (" DriverKit" ))
2165
- return DarwinPlatform::createFromSDK (Darwin::DriverKit, Version);
2180
+ return DarwinPlatform::createFromSDK (isysroot, Darwin::DriverKit,
2181
+ Version);
2166
2182
return std::nullopt;
2167
2183
};
2168
2184
if (auto Result = CreatePlatformFromSDKName (SDK))
@@ -2236,7 +2252,7 @@ inferDeploymentTargetFromArch(DerivedArgList &Args, const Darwin &Toolchain,
2236
2252
if (OSTy == llvm::Triple::UnknownOS)
2237
2253
return std::nullopt;
2238
2254
return DarwinPlatform::createFromArch (
2239
- OSTy, getInferredOSVersion (OSTy, Triple, TheDriver));
2255
+ MachOArchName, OSTy, getInferredOSVersion (OSTy, Triple, TheDriver));
2240
2256
}
2241
2257
2242
2258
// / Returns the deployment target that's specified using the -target option.
@@ -2455,9 +2471,15 @@ void Darwin::AddDeploymentTarget(DerivedArgList &Args) const {
2455
2471
}
2456
2472
2457
2473
assert (PlatformAndVersion && " Unable to infer Darwin variant" );
2458
- if (!PlatformAndVersion->isValidOSVersion ())
2459
- getDriver ().Diag (diag::err_drv_invalid_version_number)
2460
- << PlatformAndVersion->getAsString (Args, Opts);
2474
+ if (!PlatformAndVersion->isValidOSVersion ()) {
2475
+ if (PlatformAndVersion->isExplicitlySpecified ())
2476
+ getDriver ().Diag (diag::err_drv_invalid_version_number)
2477
+ << PlatformAndVersion->getAsString (Args, Opts);
2478
+ else
2479
+ getDriver ().Diag (diag::err_drv_invalid_version_number_inferred)
2480
+ << PlatformAndVersion->getOSVersion ().getAsString ()
2481
+ << PlatformAndVersion->getInferredSource ();
2482
+ }
2461
2483
// After the deployment OS version has been resolved, set it to the canonical
2462
2484
// version before further error detection and converting to a proper target
2463
2485
// triple.
0 commit comments