-
Notifications
You must be signed in to change notification settings - Fork 348
[stable/20240723] Expose macros for availability domain definitions #11250
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/*===---- availability_domain.h - Availability Domain -----------------------=== | ||
* | ||
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
* See https://llvm.org/LICENSE.txt for license information. | ||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
* | ||
*===-----------------------------------------------------------------------=== | ||
*/ | ||
|
||
#ifndef __AVAILABILITY_DOMAIN_H | ||
#define __AVAILABILITY_DOMAIN_H | ||
|
||
#include <stdint.h> | ||
|
||
#define __AVAILABILITY_DOMAIN_ENABLED 0 | ||
#define __AVAILABILITY_DOMAIN_DISABLED 1 | ||
#define __AVAILABILITY_DOMAIN_DYNAMIC 2 | ||
|
||
/// Describes the fields of a Clang availability domain. This struct is an | ||
/// implementation detail of the compiler and is subject to change so don't | ||
/// reference `__AvailabilityDomain` directly. Instead, use the provided macros: | ||
/// | ||
/// CLANG_DYNAMIC_AVAILABILITY_DOMAIN(MyDomain, query); | ||
/// | ||
struct __AvailabilityDomain { | ||
/// The state of the domain (AVAILABLE, UNAVAILABLE, DYNAMIC, etc.). | ||
intptr_t state; | ||
/// An optional function pointer to call to query the availability of a domain | ||
/// at runtime. This should only be non-null for domains in the DYNAMIC state. | ||
int (*const runtimeQuery)(void); | ||
}; | ||
|
||
#define CLANG_DYNAMIC_AVAILABILITY_DOMAIN(domain, query) \ | ||
static struct __AvailabilityDomain domain __attribute__(( \ | ||
availability_domain(domain))) = {__AVAILABILITY_DOMAIN_DYNAMIC, query} | ||
|
||
#define CLANG_ENABLED_AVAILABILITY_DOMAIN(domain) \ | ||
static struct __AvailabilityDomain domain __attribute__(( \ | ||
availability_domain(domain))) = {__AVAILABILITY_DOMAIN_ENABLED, 0} | ||
|
||
#define CLANG_DISABLED_AVAILABILITY_DOMAIN(domain) \ | ||
static struct __AvailabilityDomain domain __attribute__(( \ | ||
availability_domain(domain))) = {__AVAILABILITY_DOMAIN_DISABLED, 0} | ||
|
||
#define CLANG_ALWAYS_ENABLED_AVAILABILITY_DOMAIN(domain) \ | ||
static struct __AvailabilityDomain domain __attribute__(( \ | ||
availability_domain(domain))) = {__AVAILABILITY_DOMAIN_ENABLED, 0} | ||
|
||
#define CLANG_ALWAYS_DISABLED_AVAILABILITY_DOMAIN(domain) \ | ||
static struct __AvailabilityDomain domain __attribute__(( \ | ||
availability_domain(domain))) = {__AVAILABILITY_DOMAIN_DISABLED, 0} | ||
|
||
#endif /* __AVAILABILITY_DOMAIN_H */ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,24 +10,8 @@ | |
#ifndef __FEATURE_AVAILABILITY_H | ||
#define __FEATURE_AVAILABILITY_H | ||
|
||
#include <stdint.h> | ||
// feature-availability.h is deprecated - use availability_domain.h instead. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we turn this comment into a real warning using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd rather have a chance to move adopters off of it before it becomes a warning (although once adopters move off of it we should probably remove it entirely). |
||
|
||
/// The possible availability domain states. These values are hardcoded in the | ||
/// compiler and reproduced here for convenience when defining domains. | ||
|
||
#define __AVAILABILITY_DOMAIN_ENABLED 0 | ||
#define __AVAILABILITY_DOMAIN_DISABLED 1 | ||
#define __AVAILABILITY_DOMAIN_DYNAMIC 2 | ||
|
||
/// A struct describing availability domain definitions. This struct definition | ||
/// is just a convenience to ensure that a header defining an availability | ||
/// domain can define it with the arguments that Clang expects at parse time. | ||
struct __AvailabilityDomain { | ||
/// The state of the domain (AVAILABLE, UNAVAILABLE, DYNAMIC, etc.). | ||
intptr_t state; | ||
/// An optional function pointer to call to query the availability of a domain | ||
/// at runtime. This should only be non-null for domains in the DYNAMIC state. | ||
int (*const runtimeQuery)(void); | ||
}; | ||
#include <availability_domain.h> | ||
|
||
#endif /* __FEATURE_AVAILABILITY_H */ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
#ifndef FEATURE1_H | ||
#define FEATURE1_H | ||
#include <feature-availability.h> | ||
#include <availability_domain.h> | ||
|
||
static struct __AvailabilityDomain feature1 __attribute__((availability_domain(feature1))) = {__AVAILABILITY_DOMAIN_ENABLED, 0}; | ||
CLANG_ENABLED_AVAILABILITY_DOMAIN(feature1); | ||
|
||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
#ifndef FEATURE2_H | ||
#define FEATURE2_H | ||
#include <feature-availability.h> | ||
#include <availability_domain.h> | ||
#include "feature1.h" | ||
|
||
static struct __AvailabilityDomain feature2 __attribute__((availability_domain(feature2))) = {__AVAILABILITY_DOMAIN_DISABLED, 0}; | ||
CLANG_DISABLED_AVAILABILITY_DOMAIN(feature2); | ||
|
||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a drive-by fix for a compiler crash I encountered when testing an earlier version of this PR.