opcodes: fix Werror=format build breaker in opcodes/riscv-dis.c

Message ID 20241122163701.31772-1-tdevries@suse.de
State New
Headers
Series opcodes: fix Werror=format build breaker in opcodes/riscv-dis.c |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_binutils_check--master-aarch64 success Test passed
linaro-tcwg-bot/tcwg_binutils_check--master-arm success Test passed

Commit Message

Tom de Vries Nov. 22, 2024, 4:37 p.m. UTC
  I build gdb on arm-linux and ran into:
...
  CC       riscv-dis.lo
opcodes/riscv-dis.c: In function ‘print_insn_args’:
opcodes/riscv-dis.c:743:29: error: format ‘%lu’ expects argument of type \
  ‘long unsigned int’, but argument 4 has type ‘insn_t’ \
  {aka ‘long long unsigned int’} [-Werror=format=]
  743 |                          "%lu", EXTRACT_ZCMT_INDEX (l));
      |                           ~~^
      |                             |
      |                             long unsigned int
      |                           %llu
...

Fix this by printing the insn_t value, which is a uint64_t, using PRIu64.

Tested by finishing the build.
---
 opcodes/riscv-dis.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)


base-commit: 8a7f13063a6d5314cfde5b4f1dc49afa2922cf8c
  

Comments

Nelson Chu Nov. 23, 2024, 2:59 p.m. UTC | #1
Thanks, looks good to me.

Nelson

On Sat, Nov 23, 2024 at 12:38 AM Tom de Vries <tdevries@suse.de> wrote:

> I build gdb on arm-linux and ran into:
> ...
>   CC       riscv-dis.lo
> opcodes/riscv-dis.c: In function ‘print_insn_args’:
> opcodes/riscv-dis.c:743:29: error: format ‘%lu’ expects argument of type \
>   ‘long unsigned int’, but argument 4 has type ‘insn_t’ \
>   {aka ‘long long unsigned int’} [-Werror=format=]
>   743 |                          "%lu", EXTRACT_ZCMT_INDEX (l));
>       |                           ~~^
>       |                             |
>       |                             long unsigned int
>       |                           %llu
> ...
>
> Fix this by printing the insn_t value, which is a uint64_t, using PRIu64.
>
> Tested by finishing the build.
> ---
>  opcodes/riscv-dis.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/opcodes/riscv-dis.c b/opcodes/riscv-dis.c
> index 101380f93aa..c1212b14a05 100644
> --- a/opcodes/riscv-dis.c
> +++ b/opcodes/riscv-dis.c
> @@ -740,7 +740,7 @@ print_insn_args (const char *oparg, insn_t l, bfd_vma
> pc, disassemble_info *info
>                 case 'i':
>                 case 'I':
>                   print (info->stream, dis_style_address_offset,
> -                        "%lu", EXTRACT_ZCMT_INDEX (l));
> +                        "%" PRIu64, EXTRACT_ZCMT_INDEX (l));
>                   break;
>                 default:
>                   goto undefined_modifier;
>
> base-commit: 8a7f13063a6d5314cfde5b4f1dc49afa2922cf8c
> --
> 2.35.3
>
>
  

Patch

diff --git a/opcodes/riscv-dis.c b/opcodes/riscv-dis.c
index 101380f93aa..c1212b14a05 100644
--- a/opcodes/riscv-dis.c
+++ b/opcodes/riscv-dis.c
@@ -740,7 +740,7 @@  print_insn_args (const char *oparg, insn_t l, bfd_vma pc, disassemble_info *info
 		case 'i':
 		case 'I':
 		  print (info->stream, dis_style_address_offset,
-			 "%lu", EXTRACT_ZCMT_INDEX (l));
+			 "%" PRIu64, EXTRACT_ZCMT_INDEX (l));
 		  break;
 		default:
 		  goto undefined_modifier;