[clang] [clang][Darwin] Simplify deployment version assignment in the Driver (PR #142013)

Cyndy Ishida via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 4 14:58:55 PDT 2025


================
@@ -1938,11 +1942,22 @@ struct DarwinPlatform {
   SourceKind Kind;
   DarwinPlatformKind Platform;
   DarwinEnvironmentKind Environment = DarwinEnvironmentKind::NativeEnvironment;
-  VersionTuple NativeTargetVersion;
-  std::string OSVersion;
-  bool HasOSVersion = true, InferSimulatorFromArch = true;
+  // When compiling for a zippered target, this means both target &
+  // target variant is set on the command line, ZipperedOSVersion holds the
+  // OSVersion tied to the main target value.
+  VersionTuple ZipperedOSVersion;
+  // We allow multiple ways to set or default the OS
+  // version used for compilation. The ResolvedOSVersion always represents what
+  // will be used.
+  VersionTuple ResolvedOSVersion;
----------------
cyndyishida wrote:

 I think `DarwinPlatform` is intended to be a lightweight type for representing platform info from various arguments, while `Darwin::AddDeploymentTarget` is the core logic for mapping it back to the target triple for CC1.  It has direct access to objects like the `Driver` to be able to report errors when attempting to resolve the OS version. For now, I want to preserve that behavior. 

However, to address the overarching concerns I have: 
* changed `VersionTuple ResolvedOSVersion` to `std::optional<VersionTuple> UnderlyingOSVersion`
* replaced `providedOSVersion` with `hasOSVersion` and simplified setting UnderlyingOSVersion, to no longer worry about what existed at the construction of the `DarwinPlatform` object.
* Introduce `takeOSVersion()` that should be called when the driver has resolved the OSVersion as far as the `DarwinPlatform` object is concerned. 
* renamed an unrelated `getOSVersion` to `getInferredOSVersion`

https://github.com/llvm/llvm-project/pull/142013


More information about the cfe-commits mailing list