Skip to content

Commit 50da3b8

Browse files
[clang] Add __has_extension(swiftcc) support
This patch adds `swiftcc` extension to check if the target supports Swift calling convention as well as we do for `swiftasynccc`. Also `swiftasynccc` is now considered to be a Clang extension rather than a language standard feature to reflect the nature of the attribute.
1 parent 2ad9706 commit 50da3b8

File tree

4 files changed

+25
-6
lines changed

4 files changed

+25
-6
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,12 @@ for the full list.
215215

216216
This allows the ``_Nullable`` and ``_Nonnull` family of type attributes to
217217
apply to this class.
218+
- The ``swiftasynccc`` attribute is now considered to be a Clang extension
219+
rather than a language standard feature. Please use
220+
``__has_extension(swiftasynccc)`` to check the availability of this attribute
221+
for the target platform instead of ``__has_feature(swiftasynccc)``. Also,
222+
added a new extension query ``__has_extension(swiftcc)`` corresponding to the
223+
``__attribute__((swiftcc))`` attribute.
218224

219225
Improvements to Clang's diagnostics
220226
-----------------------------------

clang/include/clang/Basic/AttrDocs.td

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

51645164
Support for this feature is target-dependent, although it should be
5165-
supported on every target that Swift supports. Query for this support
5166-
with ``__has_attribute(swiftcall)``. This implies support for the
5167-
``swift_context``, ``swift_error_result``, and ``swift_indirect_result``
5168-
attributes.
5165+
supported on every target that Swift supports. Query for this attribute
5166+
with ``__has_attribute(swiftcall)``. Query if the target supports the
5167+
calling convention with ``__has_extension(swiftcc)``. This implies
5168+
support for the ``swift_context``, ``swift_error_result``, and
5169+
``swift_indirect_result`` attributes.
51695170
}];
51705171
}
51715172

@@ -5212,6 +5213,10 @@ the following:
52125213
semantically be performed after a guaranteed tail call, such as the
52135214
non-trivial destruction of a local variable or temporary,
52145215
then the program is ill-formed.
5216+
5217+
Query for this attribute with ``__has_attribute(swiftasynccall)``. Query if
5218+
the target supports the calling convention with
5219+
``__has_extension(swiftasynccc)``.
52155220
}];
52165221
}
52175222

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(memory_sanitizer,
102102
FEATURE(thread_sanitizer, LangOpts.Sanitize.has(SanitizerKind::Thread))
103103
FEATURE(dataflow_sanitizer, LangOpts.Sanitize.has(SanitizerKind::DataFlow))
104104
FEATURE(scudo, LangOpts.Sanitize.hasOneOf(SanitizerKind::Scudo))
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: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
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) {}

0 commit comments

Comments
 (0)