Skip to content

clang can't compile headers from the MacOSX14 SDK when targeting catalyst #64438

Closed
@nico

Description

This builds with Xcode 14's clang, but not with open-source clang:

% cat test.m
#import <UIKit/UIKit.h>

% path/to/clang++  -std=c++11 -target arm64-apple-ios16.6-macabi -isysroot sdk/xcode_links/MacOSX14.0.sdk -isystem sdk/xcode_links/MacOSX14.0.sdk/System/iOSSupport/usr/include -iframework sdk/xcode_links/MacOSX14.0.sdk/System/iOSSupport/System/Library/Frameworks ~/Desktop/foo.mm  -o ~/Desktop/foo.a
…
sdk/xcode_links/MacOSX14.0.sdk/System/Library/Frameworks/FileProvider.framework/Headers/NSFileProviderItem.h:127:32: error: 'NSFileProviderItemCapabilities' is unavailable: not available on macCatalyst
  127 | typedef NS_OPTIONS(NSUInteger, NSFileProviderItemCapabilities) {
      |                                ^

The diagnostic is correct! NSFileProviderItem.h does:

FILEPROVIDER_API_AVAILABILITY_V2_V3
typedef NS_OPTIONS(NSUInteger, NSFileProviderItemCapabilities) {

And NSFileProviderDefines.h does:

#define FILEPROVIDER_API_AVAILABILITY_V2_V3 API_AVAILABLE(ios(11.0), macos(11.0)) API_UNAVAILABLE(macCatalyst) API_UNAVAILABLE(watchos, tvos)

This expands to

__attribute__((availability(ios,introduced=11.0))) __attribute__((availability(macos,introduced=11.0))) __attribute__((availability(macCatalyst,unavailable))) __attribute__((availability(watchos,unavailable))) __attribute__((availability(tvos,unavailable)))

and it does mark NSFileProviderItemCapabilities as unavailable on macCatalyst.

In the 13.3 SDK, CFAvailability.h did:

#define CF_OPTIONS(_type, _name) _type _name; enum __CF_OPTIONS_ATTRIBUTES : _type

But in the 14.0 SDK, it instead does:

+#define CF_OPTIONS(_type, _name) _type _name; enum __CF_OPTIONS_ATTRIBUTES : _name

That is, previously the enum values were in an unnamed enum with underlying type NSUInteger, but now they're in an unnamed enum with underlying type NSFileProviderItemCapabilities. NSFileProviderItemCapabilities is unavailable and now referenced, so clang warns.

Here's a reduced repro based on that:

% cat repro.mm
#define CF_OPTIONS(_type, _name) enum : _name

__attribute__((availability(macos,introduced=11.0)))
__attribute__((availability(macCatalyst,unavailable))) 
typedef unsigned NSFileProviderItemCapabilities;

CF_OPTIONS(unsigned, NSFileProviderItemCapabilities) {
  A = 0,
};
% out/gn/bin/clang -std=c++17 -target arm64-apple-ios16.6-macabi repro.mm -isysroot ~/Downloads/MacOSX14.sdk   -c
repro.mm:7:22: error: 'NSFileProviderItemCapabilities' is unavailable: not available on macCatalyst
    7 | CF_OPTIONS(unsigned, NSFileProviderItemCapabilities) {
      |                      ^
repro.mm:5:18: note: 'NSFileProviderItemCapabilities' has been explicitly marked unavailable here
    5 | typedef unsigned NSFileProviderItemCapabilities;
      |                  ^
1 error generated.

Xcode 13.3's clang diags the same way on this repro. But Xcode 14's doesn't:

% /Users/thakis/Downloads/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -std=c++17 -target arm64-apple-ios16.6-macabi repro.mm -isysroot ~/Downloads/MacOSX14.sdk -c
# no diag

But if I remove the CF_OPTIONS macro and inline its contents, then xcode 14's clang also diags.

So it must have some "if avail diag is for unnamed enum where both the unavail type and the enum keyword are part of a macros, then don't diag" logic I guess?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions