This patch adds CodeGen support for @available on macos. This is done by compiling @available predicates into calls to clang.is_os_version_at_least. This function first populates 3 global variables which hold the major, minor and subminor with the operating system version, using core services' Gestalt() (https://developer.apple.com/reference/coreservices/1471624-gestalt?language=objc), and grand central dispatch's dispatch_once_f to make sure that this is only done once. After that, it compares the version that was passed to it with the host's OS version.
Unfortunately, Gestalt() is only available on macOS. In a follow-up patch, we can add support for other platforms. I think that the best way of doing that is to depend on Objective-C's NSProcessInfo. I'm not super familiar with this part of the compiler, and in particular I'm unsure of whether we should be directly calling into library functions like Gestalt and dispatch_once_f, so please tear this patch apart!
This patch is part of a feature that I proposed last summer here:
http://lists.llvm.org/pipermail/cfe-dev/2016-July/049851.html
Thanks,
Erik
You can move this line after the if below since these Min and SMin are used only after the if.