Skip to content

Clang MIPS: float register constraints for inline asm deviate from gcc #64241

Closed
@shravanrn

Description

@shravanrn

clang and gcc seem to have different behavior of floating point constraints for inline asm targetting MIPS. Consider this simple example

// gcc compiles this but clang does not
void read_float(float* p) {
    float result = *p;
    __asm__("" ::"r"(result));
}

The following code compiles fine on gcc when targeting MIPS, but clang gives a compile error couldn't allocate input reg for constraint 'r'

Clang requires the register constraint here to be "f" not "r". However applying an "f" constraint, causes gcc to fail compilation with the error error: impossible constraint in 'asm' while clang compiles the code fine.

// clang compiles this but gcc does not
void read_float(float* p) {
    float result = *p;
    __asm__("" ::"f"(result));
}

Here is a simple demo of the issue: https://godbolt.org/z/WGWxd3ejo
Test with "mips gcc 13.1.0" and "mips clang 16.0.0"

(This bug was discovered as part of the wasm2c project WebAssembly/wabt#2266)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions