llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Alsey Coleman Miller (colemancda)

<details>
<summary>Changes</summary>

Compiling anything for MIPS with the Swift calling convention currently fails 
in two places.

`MipsTargetInfo` does not override `checkCallingConvention`, so it inherits the 
base implementation that accepts only `CC_C`. Sema drops `swiftcall` with 
`-Wignored-attributes` and substitutes the default convention, after which 
every `swift_context` parameter is a hard error:

```
error: 'swift_context' parameter can only be used with swiftcall or
swiftasynccall calling convention
```

Past that, `MIPSTargetCodeGenInfo` registers no `SwiftABIInfo`, so CodeGen 
asserts with "Swift ABI info has not been initialized".

This accepts `CC_Swift` and registers a `SwiftABIInfo`. No separate argument 
assignment is needed: the convention is lowered like the C convention, and 
`SwiftErrorInRegister` is false so the error is passed indirectly. The MIPS 
backend needs no change - it has no calling-convention gate in 
`LowerFormalArguments` or `LowerCall`.

`CC_SwiftAsync` is deliberately refused, as `SystemZTargetInfo` and 
`PPC64TargetInfo` refuse it: lowering it needs guaranteed tail calls that the 
backend does not provide, and `__has_extension(swiftasynccc)` is derived from 
this check, so callers fall back to `swiftcall` instead of emitting a 
convention with no lowering.

Found while building the Swift standard library for MIPS with Buildroot.

---
Full diff: https://github.com/llvm/llvm-project/pull/213446.diff


3 Files Affected:

- (modified) clang/lib/Basic/Targets/Mips.h (+12) 
- (modified) clang/lib/CodeGen/Targets/Mips.cpp (+4-1) 
- (added) clang/test/Sema/mips-swiftcall.c (+20) 


``````````diff
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<unsigned, unsigned> 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<MipsABIInfo>(CGT, IsO32)),
-        SizeOfUnwindException(IsO32 ? 24 : 32) {}
+        SizeOfUnwindException(IsO32 ? 24 : 32) {
+    SwiftInfo =
+        std::make_unique<SwiftABIInfo>(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) {}

``````````

</details>


https://github.com/llvm/llvm-project/pull/213446
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to