diff options
author | YunQiang Su <syq@debian.org> | 2024-02-27 14:08:36 +0800 |
---|---|---|
committer | Tom Stellard <tstellar@redhat.com> | 2024-02-27 09:18:54 -0800 |
commit | 461274b81d8641eab64d494accddc81d7db8a09e (patch) | |
tree | e1be320fbeea1122cd0d243440f8463cf003ac68 /clang | |
parent | e2182a6b91f5001bd9b52e3b1fe6beac434e5fe5 (diff) | |
download | llvm-461274b81d8641eab64d494accddc81d7db8a09e.zip llvm-461274b81d8641eab64d494accddc81d7db8a09e.tar.gz llvm-461274b81d8641eab64d494accddc81d7db8a09e.tar.bz2 |
MIPS: Fix asm constraints "f" and "r" for softfloat (#79116)llvmorg-18.1.0-rc4llvmorg-18.1.0
This include 2 fixes:
1. Disallow 'f' for softfloat.
2. Allow 'r' for softfloat.
Currently, 'f' is accpeted by clang, then LLVM meets an internal error.
'r' is rejected by LLVM by: couldn't allocate input reg for constraint
'r'.
Fixes: #64241, #63632
---------
Co-authored-by: Fangrui Song <i@maskray.me>
(cherry picked from commit c88beb4112d5bbf07d76a615ab7f13ba2ba023e6)
Diffstat (limited to 'clang')
-rw-r--r-- | clang/lib/Basic/Targets/Mips.h | 4 | ||||
-rw-r--r-- | clang/test/CodeGen/Mips/inline-asm-constraints.c | 11 | ||||
-rw-r--r-- | clang/test/Sema/inline-asm-validate-mips.c | 9 |
3 files changed, 23 insertions, 1 deletions
diff --git a/clang/lib/Basic/Targets/Mips.h b/clang/lib/Basic/Targets/Mips.h index f46b95a..23d4e1b 100644 --- a/clang/lib/Basic/Targets/Mips.h +++ b/clang/lib/Basic/Targets/Mips.h @@ -237,12 +237,14 @@ public: case 'r': // CPU registers. case 'd': // Equivalent to "r" unless generating MIPS16 code. case 'y': // Equivalent to "r", backward compatibility only. - case 'f': // floating-point registers. case 'c': // $25 for indirect jumps case 'l': // lo register case 'x': // hilo register pair Info.setAllowsRegister(); return true; + case 'f': // floating-point registers. + Info.setAllowsRegister(); + return FloatABI != SoftFloat; case 'I': // Signed 16-bit constant case 'J': // Integer 0 case 'K': // Unsigned 16-bit constant diff --git a/clang/test/CodeGen/Mips/inline-asm-constraints.c b/clang/test/CodeGen/Mips/inline-asm-constraints.c new file mode 100644 index 0000000..88afe87 --- /dev/null +++ b/clang/test/CodeGen/Mips/inline-asm-constraints.c @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -emit-llvm -triple mips -target-feature +soft-float %s -o - | FileCheck %s --check-prefix=SOFT_FLOAT + +// SOFT_FLOAT: call void asm sideeffect "", "r,~{$1}"(float %1) +void read_float(float *p) { + __asm__("" ::"r"(*p)); +} + +// SOFT_FLOAT: call void asm sideeffect "", "r,~{$1}"(double %1) +void read_double(double *p) { + __asm__("" :: "r"(*p)); +} diff --git a/clang/test/Sema/inline-asm-validate-mips.c b/clang/test/Sema/inline-asm-validate-mips.c new file mode 100644 index 0000000..7da248f --- /dev/null +++ b/clang/test/Sema/inline-asm-validate-mips.c @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -triple mips64 -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple mips64 -target-feature +soft-float -fsyntax-only -verify=softfloat %s + +// expected-no-diagnostics + +void test_f(float p) { + float result = p; + __asm__("" :: "f"(result)); // softfloat-error{{invalid input constraint 'f' in asm}} +} |