Skip to content

Clang does not process visionOS (xros) availability correctly #10782

@stuartcarnie

Description

@stuartcarnie

The following snippet of Objective-C code, which declares the typedef as available on watchOS, and unavailable on iOS, macOS and tvOS platforms:

#import <Foundation/Foundation.h>

API_UNAVAILABLE(visionos) @interface Foo
@end

typedef void(^Bar)(Foo *foo) API_AVAILABLE(watchos(5.0)) API_UNAVAILABLE(ios,macos,tvos);

Given iOS is unavailable, it also includes derivatives, which means visionOS.

Compiling this snippet with Apple's clang compiler works as expected:

echo "#import <Foundation/Foundation.h>\nAPI_UNAVAILABLE(visionos) @interface Foo\n@end\n typedef void(^Bar)(Foo *foo) API_AVAILABLE(watchos(5.0)) API_UNAVAILABLE(ios,macos,tvos);" | xcrun -sdk xros clang -mtargetos=xros2.5 -O2 -x objective-c -c -o test.o -

However, compiling with clang from here fails:

echo -e "#import <Foundation/Foundation.h>\nAPI_UNAVAILABLE(visionos) @interface Foo\n@end\ntypedef void(^Bar)(Foo *foo) API_AVAILABLE(watchos(5.0)) API_UNAVAILABLE(ios,macos,tvos);" | arm-apple-darwin11-clang -isysroot /root/SDKs/XROS2.5.sdk/ -mtargetos=xros2.5 -O2 -x objective-c -c -o test.o -

Output:

<stdin>:4:20: error: 'Foo' is unavailable: not available on visionOS
    4 | typedef void(^Bar)(Foo *foo) API_AVAILABLE(watchos(5.0)) API_UNAVAILABLE(ios,macos,tvos);
      |                    ^                                                                                                                                          <stdin>:2:38: note: 'Foo' has been explicitly marked unavailable here                                                                                                     2 | API_UNAVAILABLE(visionos) @interface Foo
      |                                      ^
1 error generated.

If I explicitly add visionos to the typedef declaration, it passes.

Unfortunately, this problem occurs when compiling Apple's SDKs, such as CoreMotion with llvm / clang, that has declarations such as:

/*!
 * @typedef CMDyskineticSymptomResultHandler
 * @brief Completion handler for CMDyskineticSymptomResult values.
 */
typedef void(^CMDyskineticSymptomResultHandler)(NSArray<CMDyskineticSymptomResult *> * _Nonnull dyskineticSymptomResult, NSError * _Nullable error) API_AVAILABLE(watchos(5.0)) API_UNAVAILABLE(ios, macos, tvos);

Note

This is a copy of llvm#142502, as I realise I am using a build from the Apple fork of llvm via https://github.com/tpoechtrager/osxcross.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions