Skip to content

Commit ede4955

Browse files
committed
Merge commit 'f58afc8d6441' from apple/stable/20210628 into swift/rebranch
2 parents f4be1cf + f58afc8 commit ede4955

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+608
-90
lines changed

clang/include/clang-c/Index.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
* compatible, thus CINDEX_VERSION_MAJOR is expected to remain stable.
3434
*/
3535
#define CINDEX_VERSION_MAJOR 0
36-
#define CINDEX_VERSION_MINOR 61
36+
#define CINDEX_VERSION_MINOR 62
3737

3838
#define CINDEX_VERSION_ENCODE(major, minor) (((major)*10000) + ((minor)*1))
3939

@@ -3418,6 +3418,7 @@ enum CXCallingConv {
34183418
CXCallingConv_PreserveMost = 14,
34193419
CXCallingConv_PreserveAll = 15,
34203420
CXCallingConv_AArch64VectorCall = 16,
3421+
CXCallingConv_SwiftAsync = 17,
34213422

34223423
CXCallingConv_Invalid = 100,
34233424
CXCallingConv_Unexposed = 200

clang/include/clang/Basic/Attr.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2513,6 +2513,11 @@ def SwiftCall : DeclOrTypeAttr {
25132513
let Documentation = [SwiftCallDocs];
25142514
}
25152515

2516+
def SwiftAsyncCall : DeclOrTypeAttr {
2517+
let Spellings = [Clang<"swiftasynccall">];
2518+
let Documentation = [SwiftAsyncCallDocs];
2519+
}
2520+
25162521
def SwiftContext : ParameterABIAttr {
25172522
let Spellings = [Clang<"swift_context">];
25182523
let Documentation = [SwiftContextDocs];

clang/include/clang/Basic/AttrDocs.td

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4686,7 +4686,8 @@ def SwiftContextDocs : Documentation {
46864686
let Category = DocCatVariable;
46874687
let Content = [{
46884688
The ``swift_context`` attribute marks a parameter of a ``swiftcall``
4689-
function as having the special context-parameter ABI treatment.
4689+
or ``swiftasynccall`` function as having the special context-parameter
4690+
ABI treatment.
46904691

46914692
This treatment generally passes the context value in a special register
46924693
which is normally callee-preserved.
@@ -4699,14 +4700,39 @@ A context parameter must have pointer or reference type.
46994700
}];
47004701
}
47014702

4703+
def SwiftAsyncCallDocs : Documentation {
4704+
let Category = DocCatVariable;
4705+
let Content = [{
4706+
The ``swiftasynccall`` attribute indicates that a function is
4707+
compatible with the low-level conventions of Swift async functions,
4708+
provided it declares the right formal arguments.
4709+
4710+
In most respects, this is similar to the ``swiftcall`` attribute, except for
4711+
the following:
4712+
- A parameter may be marked ``swift_async_context``, ``swift_context``
4713+
or ``swift_indirect_result`` (with the same restrictions on parameter
4714+
ordering as ``swiftcall``) but the parameter attribute
4715+
``swift_error_result`` is not permitted.
4716+
- A ``swiftasynccall`` function must have return type ``void``.
4717+
- Within a ``swiftasynccall`` function, a call to a ``swiftasynccall``
4718+
function that is the immediate operand of a ``return`` statement is
4719+
guaranteed to be performed as a tail call. This syntax is allowed even
4720+
in C as an extension (a call to a void-returning function cannot be a
4721+
return operand in standard C). If something in the calling function would
4722+
semantically be performed after a guaranteed tail call, such as the
4723+
non-trivial destruction of a local variable or temporary,
4724+
then the program is ill-formed.
4725+
}];
4726+
}
4727+
47024728
def SwiftAsyncContextDocs : Documentation {
47034729
let Category = DocCatVariable;
47044730
let Content = [{
4705-
The ``swift_async_context`` attribute marks a parameter as having the
4706-
special asynchronous context-parameter ABI treatment.
4731+
The ``swift_async_context`` attribute marks a parameter of a ``swiftasynccall``
4732+
function as having the special asynchronous context-parameter ABI treatment.
47074733

4708-
This treatment generally passes the context value in a special register
4709-
which is normally callee-preserved.
4734+
If the function is not ``swiftasynccall``, this attribute only generates
4735+
extended frame information.
47104736

47114737
A context parameter must have pointer or reference type.
47124738
}];
@@ -4751,7 +4777,8 @@ def SwiftIndirectResultDocs : Documentation {
47514777
let Category = DocCatVariable;
47524778
let Content = [{
47534779
The ``swift_indirect_result`` attribute marks a parameter of a ``swiftcall``
4754-
function as having the special indirect-result ABI treatment.
4780+
or ``swiftasynccall`` function as having the special indirect-result ABI
4781+
treatment.
47554782

47564783
This treatment gives the parameter the target's normal indirect-result
47574784
ABI treatment, which may involve passing it differently from an ordinary

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3213,7 +3213,8 @@ def warn_nsdictionary_duplicate_key : Warning<
32133213
def note_nsdictionary_duplicate_key_here : Note<
32143214
"previous equal key is here">;
32153215
def err_swift_param_attr_not_swiftcall : Error<
3216-
"'%0' parameter can only be used with swiftcall calling convention">;
3216+
"'%0' parameter can only be used with swiftcall%select{ or swiftasynccall|}1 "
3217+
"calling convention%select{|s}1">;
32173218
def err_swift_indirect_result_not_first : Error<
32183219
"'swift_indirect_result' parameters must be first parameters of function">;
32193220
def err_swift_error_result_not_after_swift_context : Error<

clang/include/clang/Basic/Features.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ FEATURE(ptrauth_calls, LangOpts.PointerAuthCalls)
100100
FEATURE(ptrauth_returns, LangOpts.PointerAuthReturns)
101101
FEATURE(ptrauth_indirect_gotos, LangOpts.PointerAuthIndirectGotos)
102102
FEATURE(scudo, LangOpts.Sanitize.hasOneOf(SanitizerKind::Scudo))
103+
FEATURE(swiftasynccc, PP.getTargetInfo().isSwiftAsyncCCSupported())
103104
// Objective-C features
104105
FEATURE(objc_arr, LangOpts.ObjCAutoRefCount) // FIXME: REMOVE?
105106
FEATURE(objc_arc, LangOpts.ObjCAutoRefCount)

clang/include/clang/Basic/Specifiers.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ namespace clang {
266266
CC_SpirFunction, // default for OpenCL functions on SPIR target
267267
CC_OpenCLKernel, // inferred for OpenCL kernels
268268
CC_Swift, // __attribute__((swiftcall))
269+
CC_SwiftAsync, // __attribute__((swiftasynccall))
269270
CC_PreserveMost, // __attribute__((preserve_most))
270271
CC_PreserveAll, // __attribute__((preserve_all))
271272
CC_AArch64VectorCall, // __attribute__((aarch64_vector_pcs))
@@ -284,6 +285,7 @@ namespace clang {
284285
case CC_SpirFunction:
285286
case CC_OpenCLKernel:
286287
case CC_Swift:
288+
case CC_SwiftAsync:
287289
return false;
288290
default:
289291
return true;

clang/include/clang/Basic/TargetInfo.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1164,7 +1164,7 @@ class TargetInfo : public virtual TransferrableTargetInfo,
11641164
/// Apply changes to the target information with respect to certain
11651165
/// language options which change the target configuration and adjust
11661166
/// the language based on the target options where applicable.
1167-
virtual void adjust(LangOptions &Opts);
1167+
virtual void adjust(DiagnosticsEngine &Diags, LangOptions &Opts);
11681168

11691169
/// Adjust target options based on codegen options.
11701170
virtual void adjustTargetOptions(const CodeGenOptions &CGOpts,
@@ -1476,6 +1476,18 @@ class TargetInfo : public virtual TransferrableTargetInfo,
14761476

14771477
virtual CallingConvKind getCallingConvKind(bool ClangABICompat4) const;
14781478

1479+
/// \brief Is the Swift async calling convention supported for this target.
1480+
bool isSwiftAsyncCCSupported() const {
1481+
auto &triple = getTriple();
1482+
return triple.getArch() == llvm::Triple::x86_64 ||
1483+
triple.isARM() ||
1484+
triple.isAArch64();
1485+
}
1486+
1487+
CallingConvCheckResult checkSwiftAsyncCCSupported() const {
1488+
return isSwiftAsyncCCSupported() ? CCCR_OK : CCCR_Error;
1489+
}
1490+
14791491
/// Controls if __builtin_longjmp / __builtin_setjmp can be lowered to
14801492
/// llvm.eh.sjlj.longjmp / llvm.eh.sjlj.setjmp.
14811493
virtual bool hasSjLjLowering() const {

clang/include/clang/CodeGen/SwiftCallingConv.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
//
77
//===----------------------------------------------------------------------===//
88
//
9-
// Defines constants and types related to Swift ABI lowering.
9+
// Defines constants and types related to Swift ABI lowering. The same ABI
10+
// lowering applies to both sync and async functions.
1011
//
1112
//===----------------------------------------------------------------------===//
1213

clang/lib/AST/ItaniumMangle.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3109,6 +3109,8 @@ StringRef CXXNameMangler::getCallingConvQualifierName(CallingConv CC) {
31093109
return "ms_abi";
31103110
case CC_Swift:
31113111
return "swiftcall";
3112+
case CC_SwiftAsync:
3113+
return "swiftasynccall";
31123114
}
31133115
llvm_unreachable("bad calling convention");
31143116
}

clang/lib/AST/MicrosoftMangle.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2728,6 +2728,8 @@ void MicrosoftCXXNameMangler::mangleCallingConvention(CallingConv CC) {
27282728
// ::= J # __export __fastcall
27292729
// ::= Q # __vectorcall
27302730
// ::= S # __attribute__((__swiftcall__)) // Clang-only
2731+
// ::= T # __attribute__((__swiftasynccall__))
2732+
// // Clang-only
27312733
// ::= w # __regcall
27322734
// The 'export' calling conventions are from a bygone era
27332735
// (*cough*Win16*cough*) when functions were declared for export with
@@ -2747,6 +2749,7 @@ void MicrosoftCXXNameMangler::mangleCallingConvention(CallingConv CC) {
27472749
case CC_X86FastCall: Out << 'I'; break;
27482750
case CC_X86VectorCall: Out << 'Q'; break;
27492751
case CC_Swift: Out << 'S'; break;
2752+
case CC_SwiftAsync: Out << 'T'; break;
27502753
case CC_PreserveMost: Out << 'U'; break;
27512754
case CC_X86RegCall: Out << 'w'; break;
27522755
}

clang/lib/AST/Type.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3139,6 +3139,7 @@ StringRef FunctionType::getNameForCallConv(CallingConv CC) {
31393139
case CC_SpirFunction: return "spir_function";
31403140
case CC_OpenCLKernel: return "opencl_kernel";
31413141
case CC_Swift: return "swiftcall";
3142+
case CC_SwiftAsync: return "swiftasynccall";
31423143
case CC_PreserveMost: return "preserve_most";
31433144
case CC_PreserveAll: return "preserve_all";
31443145
}
@@ -3555,6 +3556,7 @@ bool AttributedType::isCallingConv() const {
35553556
case attr::ThisCall:
35563557
case attr::RegCall:
35573558
case attr::SwiftCall:
3559+
case attr::SwiftAsyncCall:
35583560
case attr::VectorCall:
35593561
case attr::AArch64VectorPcs:
35603562
case attr::Pascal:

clang/lib/AST/TypePrinter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -980,6 +980,9 @@ void TypePrinter::printFunctionAfter(const FunctionType::ExtInfo &Info,
980980
case CC_Swift:
981981
OS << " __attribute__((swiftcall))";
982982
break;
983+
case CC_SwiftAsync:
984+
OS << "__attribute__((swiftasynccall))";
985+
break;
983986
case CC_PreserveMost:
984987
OS << " __attribute__((preserve_most))";
985988
break;
@@ -1719,6 +1722,7 @@ void TypePrinter::printAttributedAfter(const AttributedType *T,
17191722
case attr::StdCall: OS << "stdcall"; break;
17201723
case attr::ThisCall: OS << "thiscall"; break;
17211724
case attr::SwiftCall: OS << "swiftcall"; break;
1725+
case attr::SwiftAsyncCall: OS << "swiftasynccall"; break;
17221726
case attr::VectorCall: OS << "vectorcall"; break;
17231727
case attr::Pascal: OS << "pascal"; break;
17241728
case attr::MSABI: OS << "ms_abi"; break;

clang/lib/Basic/TargetInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ bool TargetInfo::isTypeSigned(IntType T) {
347347
/// Apply changes to the target information with respect to certain
348348
/// language options which change the target configuration and adjust
349349
/// the language based on the target options where applicable.
350-
void TargetInfo::adjust(LangOptions &Opts) {
350+
void TargetInfo::adjust(DiagnosticsEngine &Diags, LangOptions &Opts) {
351351
if (Opts.NoBitFieldTypeAlign)
352352
UseBitFieldTypeAlignment = false;
353353

clang/lib/Basic/Targets/AArch64.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,8 @@ AArch64TargetInfo::checkCallingConvention(CallingConv CC) const {
586586
case CC_AArch64VectorCall:
587587
case CC_Win64:
588588
return CCCR_OK;
589+
case CC_SwiftAsync:
590+
return checkSwiftAsyncCCSupported();
589591
default:
590592
return CCCR_Warning;
591593
}
@@ -861,6 +863,8 @@ WindowsARM64TargetInfo::checkCallingConvention(CallingConv CC) const {
861863
case CC_Swift:
862864
case CC_Win64:
863865
return CCCR_OK;
866+
case CC_SwiftAsync:
867+
return checkSwiftAsyncCCSupported();
864868
default:
865869
return CCCR_Warning;
866870
}

clang/lib/Basic/Targets/AMDGPU.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,8 @@ AMDGPUTargetInfo::AMDGPUTargetInfo(const llvm::Triple &Triple,
358358
MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
359359
}
360360

361-
void AMDGPUTargetInfo::adjust(LangOptions &Opts) {
362-
TargetInfo::adjust(Opts);
361+
void AMDGPUTargetInfo::adjust(DiagnosticsEngine &Diags, LangOptions &Opts) {
362+
TargetInfo::adjust(Diags, Opts);
363363
// ToDo: There are still a few places using default address space as private
364364
// address space in OpenCL, which needs to be cleaned up, then Opts.OpenCL
365365
// can be removed from the following line.

clang/lib/Basic/Targets/AMDGPU.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : public TargetInfo {
9393

9494
void setAddressSpaceMap(bool DefaultIsPrivate);
9595

96-
void adjust(LangOptions &Opts) override;
96+
void adjust(DiagnosticsEngine &Diags, LangOptions &Opts) override;
9797

9898
uint64_t getPointerWidthV(unsigned AddrSpace) const override {
9999
if (isR600(getTriple()))

clang/lib/Basic/Targets/ARM.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,6 +1140,8 @@ ARMTargetInfo::checkCallingConvention(CallingConv CC) const {
11401140
case CC_Swift:
11411141
case CC_OpenCLKernel:
11421142
return CCCR_OK;
1143+
case CC_SwiftAsync:
1144+
return checkSwiftAsyncCCSupported();
11431145
default:
11441146
return CCCR_Warning;
11451147
}
@@ -1218,6 +1220,8 @@ WindowsARMTargetInfo::checkCallingConvention(CallingConv CC) const {
12181220
case CC_PreserveAll:
12191221
case CC_Swift:
12201222
return CCCR_OK;
1223+
case CC_SwiftAsync:
1224+
return checkSwiftAsyncCCSupported();
12211225
default:
12221226
return CCCR_Warning;
12231227
}

clang/lib/Basic/Targets/PPC.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -606,10 +606,10 @@ void PPCTargetInfo::fillValidCPUList(SmallVectorImpl<StringRef> &Values) const {
606606
Values.append(std::begin(ValidCPUNames), std::end(ValidCPUNames));
607607
}
608608

609-
void PPCTargetInfo::adjust(LangOptions &Opts) {
609+
void PPCTargetInfo::adjust(DiagnosticsEngine &Diags, LangOptions &Opts) {
610610
if (HasAltivec)
611611
Opts.AltiVec = 1;
612-
TargetInfo::adjust(Opts);
612+
TargetInfo::adjust(Diags, Opts);
613613
if (LongDoubleFormat != &llvm::APFloat::IEEEdouble())
614614
LongDoubleFormat = Opts.PPCIEEELongDouble
615615
? &llvm::APFloat::IEEEquad()

clang/lib/Basic/Targets/PPC.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class LLVM_LIBRARY_VISIBILITY PPCTargetInfo : public TargetInfo {
8989
}
9090

9191
// Set the language option for altivec based on our value.
92-
void adjust(LangOptions &Opts) override;
92+
void adjust(DiagnosticsEngine &Diags, LangOptions &Opts) override;
9393

9494
// Note: GCC recognizes the following additional cpus:
9595
// 401, 403, 405, 405fp, 440fp, 464, 464fp, 476, 476fp, 505, 740, 801,
@@ -454,6 +454,8 @@ class LLVM_LIBRARY_VISIBILITY PPC64TargetInfo : public PPCTargetInfo {
454454
switch (CC) {
455455
case CC_Swift:
456456
return CCCR_OK;
457+
case CC_SwiftAsync:
458+
return checkSwiftAsyncCCSupported();
457459
default:
458460
return CCCR_Warning;
459461
}

clang/lib/Basic/Targets/SPIR.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ class LLVM_LIBRARY_VISIBILITY SPIRTargetInfo : public TargetInfo {
135135
AddrSpaceMap = DefaultIsGeneric ? &SPIRDefIsGenMap : &SPIRDefIsPrivMap;
136136
}
137137

138-
void adjust(LangOptions &Opts) override {
139-
TargetInfo::adjust(Opts);
138+
void adjust(DiagnosticsEngine &Diags, LangOptions &Opts) override {
139+
TargetInfo::adjust(Diags, Opts);
140140
// FIXME: SYCL specification considers unannotated pointers and references
141141
// to be pointing to the generic address space. See section 5.9.3 of
142142
// SYCL 2020 specification.

clang/lib/Basic/Targets/SystemZ.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ class LLVM_LIBRARY_VISIBILITY SystemZTargetInfo : public TargetInfo {
143143
case CC_Swift:
144144
case CC_OpenCLKernel:
145145
return CCCR_OK;
146+
case CC_SwiftAsync:
147+
return checkSwiftAsyncCCSupported();
146148
default:
147149
return CCCR_Warning;
148150
}

clang/lib/Basic/Targets/WebAssembly.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,8 @@ ArrayRef<Builtin::Info> WebAssemblyTargetInfo::getTargetBuiltins() const {
234234
Builtin::FirstTSBuiltin);
235235
}
236236

237-
void WebAssemblyTargetInfo::adjust(LangOptions &Opts) {
237+
void WebAssemblyTargetInfo::adjust(DiagnosticsEngine &Diags,
238+
LangOptions &Opts) {
238239
// If the Atomics feature isn't available, turn off POSIXThreads and
239240
// ThreadModel, so that we don't predefine _REENTRANT or __STDCPP_THREADS__.
240241
if (!HasAtomics) {

clang/lib/Basic/Targets/WebAssembly.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ class LLVM_LIBRARY_VISIBILITY WebAssemblyTargetInfo : public TargetInfo {
129129
case CC_C:
130130
case CC_Swift:
131131
return CCCR_OK;
132+
case CC_SwiftAsync:
133+
return checkSwiftAsyncCCSupported();
132134
default:
133135
return CCCR_Warning;
134136
}
@@ -138,7 +140,7 @@ class LLVM_LIBRARY_VISIBILITY WebAssemblyTargetInfo : public TargetInfo {
138140

139141
bool hasProtectedVisibility() const override { return false; }
140142

141-
void adjust(LangOptions &Opts) override;
143+
void adjust(DiagnosticsEngine &Diags, LangOptions &Opts) override;
142144
};
143145

144146
class LLVM_LIBRARY_VISIBILITY WebAssembly32TargetInfo

clang/lib/Basic/Targets/X86.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,8 @@ class LLVM_LIBRARY_VISIBILITY X86TargetInfo : public TargetInfo {
357357
case CC_IntelOclBicc:
358358
case CC_OpenCLKernel:
359359
return CCCR_OK;
360+
case CC_SwiftAsync:
361+
return checkSwiftAsyncCCSupported();
360362
default:
361363
return CCCR_Warning;
362364
}
@@ -723,6 +725,8 @@ class LLVM_LIBRARY_VISIBILITY X86_64TargetInfo : public X86TargetInfo {
723725
case CC_X86RegCall:
724726
case CC_OpenCLKernel:
725727
return CCCR_OK;
728+
case CC_SwiftAsync:
729+
return checkSwiftAsyncCCSupported();
726730
default:
727731
return CCCR_Warning;
728732
}
@@ -799,6 +803,8 @@ class LLVM_LIBRARY_VISIBILITY WindowsX86_64TargetInfo
799803
case CC_X86RegCall:
800804
case CC_OpenCLKernel:
801805
return CCCR_OK;
806+
case CC_SwiftAsync:
807+
return checkSwiftAsyncCCSupported();
802808
default:
803809
return CCCR_Warning;
804810
}

0 commit comments

Comments
 (0)