[PATCH] D27827: [ObjC] CodeGen support for @available on macOS

Alex Lorenz via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 16 02:56:29 PST 2016

arphaman added a comment.

I don't think that generating calls to `dispatch_once` and `Gestalt` is the right approach. Swift generates a call to `_stdlib_isOSVersionAtLeast`, so maybe we could add some function like that into compiler-rt?

`Gestalt` is also deprecated, we should use something better. Swift's `_stdlib_isOSVersionAtLeast` calls `_swift_stdlib_operatingSystemVersion` (https://github.com/apple/swift/blob/2fe4254cb712fa101a220f95b6ade8f99f43dc74/stdlib/public/core/Availability.swift) which in turn either calls `NSProcessInfo.operatingSystemVersion` or loads the version from a PLIST file (https://github.com/apple/swift/blob/3328592c20ac51a7c525a439af778a75521ab781/stdlib/public/stubs/Availability.mm). I don't think we can use Objective-C in compiler-rt though, so we probably have to use another solution. Maybe use `sysctlbyname("kern.osrelease", ...)` that returns the version of the kernel, which can be remapped into the OS version (although that seems hacky)?

Comment at: lib/CodeGen/CGExprScalar.cpp:305
+    VersionTuple Version = E->getVersion();
+    Optional<unsigned> Min = Version.getMinor(), SMin = Version.getSubminor();
You can move this line after the `if` below since these `Min` and `SMin` are used only after the if.


More information about the cfe-commits mailing list