On Tue, 3 Nov 2026 at 20:51, Ankush <[email protected]> wrote:
>
> The shift expression uses an integer constant of type int.
> When i is 31, the result sets the sign bit, and its
> conversion to int does not portably preserve the intended
> mask value.
>
> Use an unsigned long constant (1ul) for the left operand
> to ensure that the shift is performed using unsigned long.

We could mention that because QEMU uses -fwrapv this is
not undefined behaviour and won't cause us to produce a
wrong result.

> Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/2618
>
> Signed-off-by: Ankush <[email protected]>
> ---
>  disas/sparc.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/disas/sparc.c b/disas/sparc.c
> index 5689533ce1..40c1164554 100644
> --- a/disas/sparc.c
> +++ b/disas/sparc.c
> @@ -2515,7 +2515,7 @@ compare_opcodes (const void * a, const void * b)
>       another, it is important to order the opcodes in the right order.  */
>    for (i = 0; i < 32; ++i)
>      {
> -      unsigned long int x = 1 << i;
> +      unsigned long int x = 1ul << i;
>        int x0 = (match0 & x) != 0;
>        int x1 = (match1 & x) != 0;
>
> @@ -2525,7 +2525,7 @@ compare_opcodes (const void * a, const void * b)
>
>    for (i = 0; i < 32; ++i)
>      {
> -      unsigned long int x = 1 << i;
> +      unsigned long int x = 1ul << i;
>        int x0 = (lose0 & x) != 0;
>        int x1 = (lose1 & x) != 0;

Reviewed-by: Peter Maydell <[email protected]>

thanks
-- PMM

Reply via email to