Skip to content

Commit

Permalink
MIPS/clang: Disallow constraint f for softfloat
Browse files Browse the repository at this point in the history
Currently, clang accpets contraint f for softfloat, then
LLVM meet an internal error.

See: llvm#64241
  • Loading branch information
wzssyqa committed Jan 23, 2024
1 parent d386c40 commit f01ce8f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions clang/lib/Basic/Targets/Mips.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions clang/test/Driver/mips-float.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit f01ce8f

Please sign in to comment.