RISC-V: THEAD: Fix improper immediate value for MODIFY_DISP instruction on 32-bit systems.

Message ID 20240129092016.1176-1-jinma@linux.alibaba.com
State Unresolved
Headers
Series RISC-V: THEAD: Fix improper immediate value for MODIFY_DISP instruction on 32-bit systems. |

Checks

Context Check Description
snail/gcc-patch-check warning Git am fail log

Commit Message

Jin Ma Jan. 29, 2024, 9:20 a.m. UTC
  When using  '%ld' to print 'long long int' variable, 'fprintf' will
produce messy output on a 32-bit system, in an incorrect instruction
being generated, such as 'th.lwib a1,(a0),-16,4294967295'. And the
following error occurred during compilation:

Assembler messages:
Error: improper immediate value (18446744073709551615)

gcc/ChangeLog:

	* config/riscv/thead.cc (th_print_operand_address): Change %ld
	to %lld.
---
 gcc/config/riscv/thead.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Andrew Pinski Jan. 29, 2024, 9:23 a.m. UTC | #1
On Mon, Jan 29, 2024 at 1:21 AM Jin Ma <jinma@linux.alibaba.com> wrote:
>
> When using  '%ld' to print 'long long int' variable, 'fprintf' will
> produce messy output on a 32-bit system, in an incorrect instruction
> being generated, such as 'th.lwib a1,(a0),-16,4294967295'. And the
> following error occurred during compilation:
>
> Assembler messages:
> Error: improper immediate value (18446744073709551615)
>
> gcc/ChangeLog:
>
>         * config/riscv/thead.cc (th_print_operand_address): Change %ld
>         to %lld.
> ---
>  gcc/config/riscv/thead.cc | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/gcc/config/riscv/thead.cc b/gcc/config/riscv/thead.cc
> index 2955bc5f8a9..9ee6444b627 100644
> --- a/gcc/config/riscv/thead.cc
> +++ b/gcc/config/riscv/thead.cc
> @@ -1141,7 +1141,7 @@ th_print_operand_address (FILE *file, machine_mode mode, rtx x)
>        return true;
>
>      case ADDRESS_REG_WB:
> -      fprintf (file, "(%s),%ld,%u", reg_names[REGNO (addr.reg)],
> +      fprintf (file, "(%s),%lld,%u", reg_names[REGNO (addr.reg)],
>                INTVAL (addr.offset) >> addr.shift, addr.shift);


This is wrong, you should instead use HOST_WIDE_INT_PRINT_DEC or
HOST_WIDE_INT_PRINT_UNSIGNED.

Thanks,
Andrew Pinski

>         return true;
>
> --
> 2.17.1
>
  
Jin Ma Jan. 29, 2024, 9:36 a.m. UTC | #2
>On Mon, Jan 29, 2024 at 1:21=E2=80=AFAM Jin Ma <jinma@linux.alibaba.com> wr=
>ote:
>>
>> When using  '%ld' to print 'long long int' variable, 'fprintf' will
>> produce messy output on a 32-bit system, in an incorrect instruction
>> being generated, such as 'th.lwib a1,(a0),-16,4294967295'. And the
>> following error occurred during compilation:
>>
>> Assembler messages:
>> Error: improper immediate value (18446744073709551615)
>>
>> gcc/ChangeLog:
>>
>>         * config/riscv/thead.cc (th_print_operand_address): Change %ld
>>         to %lld.
>> ---
>>  gcc/config/riscv/thead.cc | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/gcc/config/riscv/thead.cc b/gcc/config/riscv/thead.cc
>> index 2955bc5f8a9..9ee6444b627 100644
>> --- a/gcc/config/riscv/thead.cc
>> +++ b/gcc/config/riscv/thead.cc
>> @@ -1141,7 +1141,7 @@ th_print_operand_address (FILE *file, machine_mode =
>mode, rtx x)
>>        return true;
>>
>>      case ADDRESS_REG_WB:
>> -      fprintf (file, "(%s),%ld,%u", reg_names[REGNO (addr.reg)],
>> +      fprintf (file, "(%s),%lld,%u", reg_names[REGNO (addr.reg)],
>>                INTVAL (addr.offset) >> addr.shift, addr.shift);


>This is wrong, you should instead use HOST_WIDE_INT_PRINT_DEC or
>HOST_WIDE_INT_PRINT_UNSIGNED.

>Thanks,
>Andrew Pinski

Yes, thank you very much for your guidance. It will be better to
use HOST_WIDE_INT_PRINT_DEC. I will make changes later :)

BR

Jin

>>         return true;
  

Patch

diff --git a/gcc/config/riscv/thead.cc b/gcc/config/riscv/thead.cc
index 2955bc5f8a9..9ee6444b627 100644
--- a/gcc/config/riscv/thead.cc
+++ b/gcc/config/riscv/thead.cc
@@ -1141,7 +1141,7 @@  th_print_operand_address (FILE *file, machine_mode mode, rtx x)
       return true;
 
     case ADDRESS_REG_WB:
-      fprintf (file, "(%s),%ld,%u", reg_names[REGNO (addr.reg)],
+      fprintf (file, "(%s),%lld,%u", reg_names[REGNO (addr.reg)],
 	       INTVAL (addr.offset) >> addr.shift, addr.shift);
 	return true;