Define __SWIFT_ATTR_SUPPORTS_MACROS when the MacrosOnImports features is available

This commit is contained in:
Doug Gregor
2024-10-08 07:00:44 -07:00
parent 70980b95f8
commit 688dd234b4
2 changed files with 14 additions and 4 deletions

View File

@@ -622,6 +622,11 @@ void importer::getNormalInvocationArguments(
if (clangSupportsPragmaAttributeWithSwiftAttr())
invocationArgStrs.push_back("-D__SWIFT_ATTR_SUPPORTS_SENDABLE_DECLS=1");
// Indicate that the compiler will respect macros applied to imported
// declarations via '__attribute__((swift_attr("@...")))'.
if (LangOpts.hasFeature(Feature::MacrosOnImports))
invocationArgStrs.push_back("-D__SWIFT_ATTR_SUPPORTS_MACROS=1");
if (triple.isXROS()) {
// FIXME: This is a gnarly hack until some macros get adjusted in the SDK.
invocationArgStrs.insert(invocationArgStrs.end(), {

View File

@@ -1,11 +1,16 @@
void async_divide(double x, double y, void (* _Nonnull completionHandler)(double x))
__attribute__((swift_attr("@macro_library.AddAsync")));
#if __SWIFT_ATTR_SUPPORTS_MACROS
#define ADD_ASYNC __attribute__((swift_attr("@macro_library.AddAsync")))
#else
#define ADD_ASYNC
#endif
void async_divide(double x, double y, void (* _Nonnull completionHandler)(double x)) ADD_ASYNC;
typedef struct SlowComputer {
} SlowComputer;
void computer_divide(const SlowComputer *computer, double x, double y, void (* _Nonnull completionHandler)(double x))
__attribute__((swift_attr("@macro_library.AddAsync")))
ADD_ASYNC
__attribute__((swift_name("SlowComputer.divide(self:_:_:completionHandler:)")));
@@ -14,7 +19,7 @@ void computer_divide(const SlowComputer *computer, double x, double y, void (* _
@interface Computer: NSObject
-(void)multiply:(double)x by:(double)y afterDone:(void (^ _Nonnull)(double x))afterDone
__attribute__((swift_attr("@macro_library.AddAsync")))
ADD_ASYNC
__attribute__((swift_async(none)));
@end
#endif