Skip to content

Conversation

ahatanaka
Copy link

This commit extends the __availability attribute to accept a feature name and a boolean-like integer argument (0 or 1) to indicate availability based on feature presence or absence.

__builtin_available and @available take a feature name as their arguments. References to annotated declarations in unguarded contexts are rejected.

For example:

 __attribute__((availability(domain:feature1, 0)))
void available_func(void);

__attribute__((availability(domain:feature1, 1)))
void unavailable_func(void);

if (__builtin_available(feature1)) {
  available_func();
  unavailable_func(); // error
} else {
  available_func(); // error
  unavailable_func();
}

rdar://137999979

This commit extends the `__availability` attribute to accept a feature
name and a boolean-like integer argument (0 or 1) to indicate
availability based on feature presence or absence.

`__builtin_available` and `@available` take a feature name as their
arguments. References to annotated declarations in unguarded contexts
are rejected.

For example:

```
__attribute__((availability(domain:feature1, 0)))
void available_func(void);

__attribute__((availability(domain:feature1, 1)))
void unavailable_func(void);

if (__builtin_available(feature1)) {
  available_func();
  unavailable_func(); // error
} else {
  available_func(); // error
  unavailable_func();
}
```

rdar://137999979
Set it in ActOnObjCAvailabilityCheckExpr instead. Without this change,
DiagnoseUnguardedFeatureAvailability scans the whole function when there
is a label in it even when there are no Decls annotated with feature
availability that are referenced in the function and there are no
ObjCAvailabilityCheckExprs.

rdar://146139827
passing it to diagnoseDeclFeatureAvailability

rdar://146139827
@ahatanaka ahatanaka requested a review from a team as a code owner March 6, 2025 00:59
@ahatanaka
Copy link
Author

@swift-ci please test llvm

@ahatanaka
Copy link
Author

@swift-ci please test

@ahatanaka ahatanaka merged commit 745ab81 into stable/20240723 Mar 6, 2025
2 of 5 checks passed
@ahatanaka ahatanaka deleted the feature-availability-20240723 branch March 6, 2025 15:28
@hjyamauchi
Copy link

@ahatanaka It appears this caused a windows CI failure: swiftlang/swift#79819
bzero may need some header file?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants