Commit 12b2682224 for qemu.org

commit 12b268222422219b21126a2ce59ba59725296f97
Author: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Date:   Sun Sep 27 13:36:47 2026 +0100

    target/i386/tcg: fix lea address calculation for CS register

    When the effective address calculation was simplified in commit 55a15eb3504
    ("target/i386/tcg: simplify effective address calculation") the refactoring
    accidentally introduced the ADDSEG() macro into the CS base address inclusion
    test.

    Fix the logic in gen_lea_v_seg_dest() to use CODE64() instead of ADDSEG() for
    the CS base address inclusion test, and at the same time split it into a switch
    statement to make the logic easier to follow.

    Fixes: 55a15eb3504 ("target/i386/tcg: simplify effective address calculation")
    Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
    Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
    Link: https://lore.kernel.org/r/20260927123807.492352-1-mark.cave-ayland@ilande.co.uk
    Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c
index b715921c37..d4ccddc33f 100644
--- a/target/i386/tcg/translate.c
+++ b/target/i386/tcg/translate.c
@@ -625,7 +625,25 @@ static void gen_lea_v_seg_dest(DisasContext *s, MemOp aflag, TCGv dest, TCGv a0,
         ovr_seg = def_seg;
     }

-    has_base = ovr_seg >= R_FS || (ovr_seg >= 0 && ADDSEG(s));
+    switch (ovr_seg) {
+    case R_DS:
+    case R_ES:
+    case R_SS:
+        has_base = ADDSEG(s);
+        break;
+    case R_CS:
+        has_base = !CODE64(s);
+        break;
+    case R_FS:
+    case R_GS:
+        has_base = true;
+        break;
+    default:
+        assert(ovr_seg < 0);
+        has_base = false;
+        break;
+    }
+
     easize = CODE64(s) ? MO_64 : MO_32;

     if (has_base) {