fix riscv64 a_cas inline asm operand sign extension
authorLuís Marques <luismarques@lowrisc.org>
Wed, 15 Jan 2020 13:24:41 +0000 (13:24 +0000)
committerRich Felker <dalias@aerifal.cx>
Wed, 22 Jan 2020 19:57:16 +0000 (14:57 -0500)
This patch adds an explicit cast to the int arguments passed to the
inline asm used in the RISC-V's implementation of `a_cas`, to ensure
that they are properly sign extended to 64 bits. They aren't
automatically sign extended by Clang, and GCC technically also doesn't
guarantee that they will be sign extended.

arch/riscv64/atomic_arch.h

index 41ad4d0..0c38258 100644 (file)
@@ -15,7 +15,7 @@ static inline int a_cas(volatile int *p, int t, int s)
                "       bnez %1, 1b\n"
                "1:"
                : "=&r"(old), "=&r"(tmp)
-               : "r"(p), "r"(t), "r"(s)
+               : "r"(p), "r"((long)t), "r"((long)s)
                : "memory");
        return old;
 }