Skip to content

Commit f01ce8f

Browse files
committed
MIPS/clang: Disallow constraint f for softfloat
Currently, clang accpets contraint f for softfloat, then LLVM meet an internal error. See: #64241
1 parent d386c40 commit f01ce8f

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

clang/lib/Basic/Targets/Mips.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,9 @@ class LLVM_LIBRARY_VISIBILITY MipsTargetInfo : public TargetInfo {
238238
case 'd': // Equivalent to "r" unless generating MIPS16 code.
239239
case 'y': // Equivalent to "r", backward compatibility only.
240240
case 'f': // floating-point registers.
241+
if (*Name == 'f' && FloatABI == SoftFloat)
242+
return false;
243+
LLVM_FALLTHROUGH;
241244
case 'c': // $25 for indirect jumps
242245
case 'l': // lo register
243246
case 'x': // hilo register pair

clang/test/Driver/mips-float.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,17 @@
102102
// CHECK-ABI-SOFT-MIPS16: "-target-feature" "+mips16"
103103
// CHECK-ABI-SOFT-MIPS16: "-msoft-float"
104104
// CHECK-ABI-SOFT-MIPS16: "-mfloat-abi" "soft"
105+
106+
/// On MIPS, don't accept constraint "f" for soft-float.
107+
// RUN: not %clang -S %s -o %t.s 2>&1 \
108+
// RUN: -target mips-linux-gnu -msoft-float \
109+
// RUN: -DSOFT_FLOAT_NO_CONSTRAINT_F \
110+
// RUN: | FileCheck --check-prefix=CHECK-SOFTFLOAT-ASM-NO-F %s
111+
// CHECK-SOFTFLOAT-ASM-NO-F: error: invalid input constraint 'f' in asm
112+
113+
#ifdef SOFT_FLOAT_NO_CONSTRAINT_F
114+
void read_float(float* p) {
115+
float result = *p;
116+
__asm__("" ::"f"(result));
117+
}
118+
#endif // SOFT_FLOAT_NO_CONSTRAINT_F

0 commit comments

Comments
 (0)