Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[MIPS] __builtin_bswap16 miscompilation #103035

Copy link
Copy link
Closed
@markus-oberhumer

Description

@markus-oberhumer
Issue body actions

(EDIT: I've added a new Godbolt link and updated the example to make it clear that the bug needs -march=mips32 to trigger)

Godbolt link: https://gcc.godbolt.org/z/vMGc86deh

clang 18.1.8 MIPS miscompilation in Debug mode

// clang -target mips-linux-musl -march=mips32 bug.c -o bug.out
// qemu-mips ./bug.out

unsigned bswap16_fails(unsigned v) {
    // FAILS - cast seems ignored ??
    return __builtin_bswap16((unsigned short) v);
}

unsigned bswap16_ok(unsigned v) {
    return __builtin_bswap16((unsigned short) (v & 0xffff)); // OK
}

int main(void) {
    if (bswap16_ok(0x04030201) != 0x0102)
        return 1;
    if (bswap16_fails(0x04030201) != 0x0102)
        return 2; // ERROR HERE
    return 0;
}

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Done
Show more project fields

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.