diff --git a/clang/lib/Basic/Targets/Mips.h b/clang/lib/Basic/Targets/Mips.h index 2f251c7eb8690..30254ff06e401 100644 --- a/clang/lib/Basic/Targets/Mips.h +++ b/clang/lib/Basic/Targets/Mips.h @@ -430,6 +430,18 @@ class LLVM_LIBRARY_VISIBILITY MipsTargetInfo : public TargetInfo { bool validateTarget(DiagnosticsEngine &Diags) const override; bool hasBitIntType() const override { return true; } + CallingConvCheckResult checkCallingConvention(CallingConv CC) const override { + switch (CC) { + case CC_C: + case CC_Swift: + return CCCR_OK; + case CC_SwiftAsync: + return CCCR_Error; + default: + return CCCR_Warning; + } + } + std::pair hardwareInterferenceSizes() const override { return std::make_pair(32, 32); } diff --git a/clang/lib/CodeGen/Targets/Mips.cpp b/clang/lib/CodeGen/Targets/Mips.cpp index c093cfc668c2e..dbe7e5f8a516d 100644 --- a/clang/lib/CodeGen/Targets/Mips.cpp +++ b/clang/lib/CodeGen/Targets/Mips.cpp @@ -57,7 +57,10 @@ class MIPSTargetCodeGenInfo : public TargetCodeGenInfo { public: MIPSTargetCodeGenInfo(CodeGenTypes &CGT, bool IsO32) : TargetCodeGenInfo(std::make_unique(CGT, IsO32)), - SizeOfUnwindException(IsO32 ? 24 : 32) {} + SizeOfUnwindException(IsO32 ? 24 : 32) { + SwiftInfo = + std::make_unique(CGT, /*SwiftErrorInRegister=*/false); + } int getDwarfEHStackPointer(CodeGen::CodeGenModule &CGM) const override { return 29; diff --git a/clang/test/Sema/mips-swiftcall.c b/clang/test/Sema/mips-swiftcall.c new file mode 100644 index 0000000000000..ff5c57868dc2f --- /dev/null +++ b/clang/test/Sema/mips-swiftcall.c @@ -0,0 +1,20 @@ +// RUN: %clang_cc1 -triple mips-unknown-linux-gnu -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple mipsel-unknown-linux-gnu -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple mips64-unknown-linux-gnuabi64 -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple mips64el-unknown-linux-gnuabi64 -fsyntax-only -verify %s + +// swiftcall is supported on MIPS; swiftasynccall is not, because the backend +// has no guaranteed tail call support for it. + +void __attribute__((swiftcall)) f(void *__attribute__((swift_context)) ctx) {} + +#if !__has_extension(swiftcc) +#error swiftcc should be available on MIPS +#endif + +#if __has_extension(swiftasynccc) +#error swiftasynccc should not be available on MIPS +#endif + +// expected-error@+1 {{'swiftasynccall' calling convention is not supported for this target}} +void __attribute__((swiftasynccall)) g(void *__attribute__((swift_async_context)) ctx) {}