Closed
Description
(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
Projects
Status
Done