[clang] MIPS/clang: Disallow constraint f for softfloat (PR #79116)

via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 23 02:21:37 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: YunQiang Su (wzssyqa)

<details>
<summary>Changes</summary>

Currently, clang accpets contraint f for softfloat, then LLVM meet an internal error.

See: #<!-- -->64241

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


2 Files Affected:

- (modified) clang/lib/Basic/Targets/Mips.h (+3) 
- (modified) clang/test/Driver/mips-float.c (+14) 


``````````diff
diff --git a/clang/lib/Basic/Targets/Mips.h b/clang/lib/Basic/Targets/Mips.h
index f46b95abfd75c73..2b8ad6645e605fc 100644
--- a/clang/lib/Basic/Targets/Mips.h
+++ b/clang/lib/Basic/Targets/Mips.h
@@ -238,6 +238,9 @@ class LLVM_LIBRARY_VISIBILITY MipsTargetInfo : public TargetInfo {
     case 'd': // Equivalent to "r" unless generating MIPS16 code.
     case 'y': // Equivalent to "r", backward compatibility only.
     case 'f': // floating-point registers.
+      if (*Name == 'f' && FloatABI == SoftFloat)
+        return false;
+      LLVM_FALLTHROUGH;
     case 'c': // $25 for indirect jumps
     case 'l': // lo register
     case 'x': // hilo register pair
diff --git a/clang/test/Driver/mips-float.c b/clang/test/Driver/mips-float.c
index 2f1b813a153224c..bbf17abfb13839f 100644
--- a/clang/test/Driver/mips-float.c
+++ b/clang/test/Driver/mips-float.c
@@ -102,3 +102,17 @@
 // CHECK-ABI-SOFT-MIPS16: "-target-feature" "+mips16"
 // CHECK-ABI-SOFT-MIPS16: "-msoft-float"
 // CHECK-ABI-SOFT-MIPS16: "-mfloat-abi" "soft"
+
+/// On MIPS, don't accept constraint "f" for soft-float.
+// RUN: not %clang -S %s -o %t.s 2>&1 \
+// RUN:     -target mips-linux-gnu -msoft-float \
+// RUN:     -DSOFT_FLOAT_NO_CONSTRAINT_F \
+// RUN:   | FileCheck --check-prefix=CHECK-SOFTFLOAT-ASM-NO-F %s
+// CHECK-SOFTFLOAT-ASM-NO-F: error: invalid input constraint 'f' in asm
+
+#ifdef SOFT_FLOAT_NO_CONSTRAINT_F
+void read_float(float* p) {
+    float result = *p;
+    __asm__("" ::"f"(result));
+}
+#endif // SOFT_FLOAT_NO_CONSTRAINT_F

``````````

</details>


https://github.com/llvm/llvm-project/pull/79116


More information about the cfe-commits mailing list