[PATCH] D27827: [ObjC] CodeGen support for @available on macOS
Erik Pilkington via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 15 13:25:27 PST 2016
erik.pilkington created this revision.
erik.pilkington added reviewers: manmanren, dexonsmith, rjmccall, thakis.
erik.pilkington added a subscriber: cfe-commits.
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
https://reviews.llvm.org/D27827
Files:
lib/CodeGen/CGExprScalar.cpp
lib/CodeGen/CGObjC.cpp
lib/CodeGen/CodeGenFunction.h
lib/CodeGen/CodeGenModule.h
test/CodeGenObjC/availability-check.m
test/CodeGenObjC/availability-check2.m
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27827.81647.patch
Type: text/x-patch
Size: 15507 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161215/f2ac8e76/attachment.bin>
More information about the cfe-commits
mailing list