Skip to content

Commit 87789f0

Browse files
Merge pull request #8441 from kateinoigakukun/katei/add-swiftcc-feature
[clang] Add `__has_extension(swiftcc)` support
2 parents db7d0a8 + ea1fea6 commit 87789f0

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
@@ -371,6 +371,13 @@ Attribute Changes in Clang
371371
supports but that are never the result of default argument promotion, such as
372372
``float``. (`#59824: <https://github.com/llvm/llvm-project/issues/59824>`_)
373373

374+
- The ``swiftasynccc`` attribute is now considered to be a Clang extension
375+
rather than a language standard feature. Please use
376+
``__has_extension(swiftasynccc)`` to check the availability of this attribute
377+
for the target platform instead of ``__has_feature(swiftasynccc)``. Also,
378+
added a new extension query ``__has_extension(swiftcc)`` corresponding to the
379+
``__attribute__((swiftcc))`` attribute.
380+
374381
Improvements to Clang's diagnostics
375382
-----------------------------------
376383
- We now generate a diagnostic for signed integer overflow due to unary minus

clang/include/clang/Basic/AttrDocs.td

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

51075107
Support for this feature is target-dependent, although it should be
5108-
supported on every target that Swift supports. Query for this support
5109-
with ``__has_attribute(swiftcall)``. This implies support for the
5110-
``swift_context``, ``swift_error_result``, and ``swift_indirect_result``
5111-
attributes.
5108+
supported on every target that Swift supports. Query for this attribute
5109+
with ``__has_attribute(swiftcall)``. Query if the target supports the
5110+
calling convention with ``__has_extension(swiftcc)``. This implies
5111+
support for the ``swift_context``, ``swift_error_result``, and
5112+
``swift_indirect_result`` attributes.
51125113
}];
51135114
}
51145115

@@ -5155,6 +5156,10 @@ the following:
51555156
semantically be performed after a guaranteed tail call, such as the
51565157
non-trivial destruction of a local variable or temporary,
51575158
then the program is ill-formed.
5159+
5160+
Query for this attribute with ``__has_attribute(swiftasynccall)``. Query if
5161+
the target supports the calling convention with
5162+
``__has_extension(swiftasynccc)``.
51585163
}];
51595164
}
51605165

clang/include/clang/Basic/Features.def

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,10 @@ FEATURE(ptrauth_calls, LangOpts.PointerAuthCalls)
108108
FEATURE(ptrauth_returns, LangOpts.PointerAuthReturns)
109109
FEATURE(ptrauth_indirect_gotos, LangOpts.PointerAuthIndirectGotos)
110110
FEATURE(scudo, LangOpts.Sanitize.hasOneOf(SanitizerKind::Scudo))
111-
FEATURE(swiftasynccc,
111+
EXTENSION(swiftcc,
112+
PP.getTargetInfo().checkCallingConvention(CC_Swift) ==
113+
clang::TargetInfo::CCCR_OK)
114+
EXTENSION(swiftasynccc,
112115
PP.getTargetInfo().checkCallingConvention(CC_SwiftAsync) ==
113116
clang::TargetInfo::CCCR_OK)
114117
// Objective-C features

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)