From 5a376999562bf43dbbbff28c2f19c634ec7f1b32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edwin=20T=C3=B6r=C3=B6k?= Date: Tue, 24 Feb 2026 09:18:40 +0100 Subject: [PATCH] tools/tests/x86_emulator: fix 'shifting a negative signed value is undefined' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit clang-21 refuses to compile this: ``` test_x86_emulator.c:1164:24: error: shifting a negative signed value is undefined [-Werror,-Wshift-negative-value] 1164 | regs.r8 = (-1L << 40) + 1; | ~~~ ^ 1 error generated. ``` The shift could also exceed the width of the type on some systems. I confirmed that both the old and the new code would produce the same value with GCC on x86-64: `0xffffff0000000001`. Signed-off-by: Edwin Török Acked-by: Jan Beulich --- tools/tests/x86_emulator/test_x86_emulator.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/tests/x86_emulator/test_x86_emulator.c b/tools/tests/x86_emulator/test_x86_emulator.c index 39e8056d77..ea507f9c3a 100644 --- a/tools/tests/x86_emulator/test_x86_emulator.c +++ b/tools/tests/x86_emulator/test_x86_emulator.c @@ -1161,7 +1161,7 @@ int main(int argc, char **argv) instr[0] = 0x4d; instr[1] = 0x0f; instr[2] = 0xbb; instr[3] = 0x03; regs.eflags = EFLAGS_ALWAYS_SET; regs.rip = (unsigned long)&instr[0]; - regs.r8 = (-1L << 40) + 1; + regs.r8 = (~0UL << 40) + 1; regs.r11 = (unsigned long)(res + (1L << 35)); rc = x86_emulate(&ctxt, &emulops); if ( (rc != X86EMUL_OKAY) ||