Skip to content

Commit 679e594

Browse files
[clang] Add __has_extension(swiftcc) support (#85347)
1 parent da2c98b commit 679e594

File tree

4 files changed

+33
-6
lines changed

4 files changed

+33
-6
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,13 @@ Attribute Changes in Clang
210210
and each must be a positive integer when provided. The parameter ``x`` is required, while ``y`` and
211211
``z`` are optional with default value of 1.
212212

213+
- The ``swiftasynccc`` attribute is now considered to be a Clang extension
214+
rather than a language standard feature. Please use
215+
``__has_extension(swiftasynccc)`` to check the availability of this attribute
216+
for the target platform instead of ``__has_feature(swiftasynccc)``. Also,
217+
added a new extension query ``__has_extension(swiftcc)`` corresponding to the
218+
``__attribute__((swiftcc))`` attribute.
219+
213220
Improvements to Clang's diagnostics
214221
-----------------------------------
215222
- Clang now applies syntax highlighting to the code snippets it

clang/include/clang/Basic/AttrDocs.td

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5137,10 +5137,11 @@ that does not. A single parameter may not have multiple ABI treatment
51375137
attributes.
51385138

51395139
Support for this feature is target-dependent, although it should be
5140-
supported on every target that Swift supports. Query for this support
5141-
with ``__has_attribute(swiftcall)``. This implies support for the
5142-
``swift_context``, ``swift_error_result``, and ``swift_indirect_result``
5143-
attributes.
5140+
supported on every target that Swift supports. Query for this attribute
5141+
with ``__has_attribute(swiftcall)``. Query if the target supports the
5142+
calling convention with ``__has_extension(swiftcc)``. This implies
5143+
support for the ``swift_context``, ``swift_error_result``, and
5144+
``swift_indirect_result`` attributes.
51445145
}];
51455146
}
51465147

@@ -5187,6 +5188,10 @@ the following:
51875188
semantically be performed after a guaranteed tail call, such as the
51885189
non-trivial destruction of a local variable or temporary,
51895190
then the program is ill-formed.
5191+
5192+
Query for this attribute with ``__has_attribute(swiftasynccall)``. Query if
5193+
the target supports the calling convention with
5194+
``__has_extension(swiftasynccc)``.
51905195
}];
51915196
}
51925197

clang/include/clang/Basic/Features.def

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,10 @@ FEATURE(thread_sanitizer, LangOpts.Sanitize.has(SanitizerKind::Thread))
102102
FEATURE(dataflow_sanitizer, LangOpts.Sanitize.has(SanitizerKind::DataFlow))
103103
FEATURE(scudo, LangOpts.Sanitize.hasOneOf(SanitizerKind::Scudo))
104104
FEATURE(ptrauth_intrinsics, LangOpts.PointerAuthIntrinsics)
105-
FEATURE(swiftasynccc,
105+
EXTENSION(swiftcc,
106+
PP.getTargetInfo().checkCallingConvention(CC_Swift) ==
107+
clang::TargetInfo::CCCR_OK)
108+
EXTENSION(swiftasynccc,
106109
PP.getTargetInfo().checkCallingConvention(CC_SwiftAsync) ==
107110
clang::TargetInfo::CCCR_OK)
108111
FEATURE(pragma_stdc_cx_limited_range, true)

clang/test/Sema/swift-call-conv.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
// RUN: %clang_cc1 -triple aarch64-unknown-windows-msvc -fsyntax-only %s -verify
22
// RUN: %clang_cc1 -triple thumbv7-unknown-windows-msvc -fsyntax-only %s -verify
33
// RUN: %clang_cc1 -triple x86_64-unknown-windows-msvc -fsyntax-only %s -verify
4+
// RISC-V does not support swiftcall
5+
// RUN: %clang_cc1 -triple riscv32-unknown-elf -fsyntax-only %s -verify
46

7+
#if __has_extension(swiftcc)
58
// expected-no-diagnostics
6-
9+
#else
10+
// expected-warning@+2 {{'__swiftcall__' calling convention is not supported for this target}}
11+
#endif
712
void __attribute__((__swiftcall__)) f(void) {}
13+
14+
#if __has_extension(swiftasynccc)
15+
// expected-no-diagnostics
16+
#else
17+
// expected-warning@+2 {{'__swiftasynccall__' calling convention is not supported for this target}}
18+
#endif
19+
void __attribute__((__swiftasynccall__)) g(void) {}

0 commit comments

Comments
 (0)