[05/13] sim/m32r: fix unused variable warning on non-Linux hosts

Message ID 20260817151646.152571-6-simon.marchi@efficios.com
State New
Headers
Series Fix various warnings when building on macOS |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-arm fail Patch failed to apply
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 fail Patch failed to apply

Commit Message

Simon Marchi Aug. 17, 2026, 3:16 p.m. UTC
  When building on macOS, I get:

    /Users/smarchi/src/binutils-gdb/sim/m32r/traps.c:191:18: error: unused variable 'cb' [-Werror,-Wunused-variable]
      191 |   host_callback *cb = STATE_CALLBACK (sd);
          |                  ^~

All the uses of `cb' in m32r_trap are inside the TRAP_LINUX_SYSCALL
case, which is guarded by `#ifdef __linux__'.  Move the declaration
inside that case, so that it only exists where it is used.

Change-Id: I609850daf7fa60d92856988dffe7e314eb1d8a30
---
 sim/m32r/traps.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Andrew Burgess Aug. 17, 2026, 3:36 p.m. UTC | #1
Simon Marchi <simon.marchi@efficios.com> writes:

> When building on macOS, I get:
>
>     /Users/smarchi/src/binutils-gdb/sim/m32r/traps.c:191:18: error: unused variable 'cb' [-Werror,-Wunused-variable]
>       191 |   host_callback *cb = STATE_CALLBACK (sd);
>           |                  ^~
>
> All the uses of `cb' in m32r_trap are inside the TRAP_LINUX_SYSCALL
> case, which is guarded by `#ifdef __linux__'.  Move the declaration
> inside that case, so that it only exists where it is used.

Approved-By: Andrew Burgess <aburgess@redhat.com>

Thanks,
Andrew

>
> Change-Id: I609850daf7fa60d92856988dffe7e314eb1d8a30
> ---
>  sim/m32r/traps.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/sim/m32r/traps.c b/sim/m32r/traps.c
> index 7b98b2453972..bb82ae80e2aa 100644
> --- a/sim/m32r/traps.c
> +++ b/sim/m32r/traps.c
> @@ -188,7 +188,6 @@ USI
>  m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
>  {
>    SIM_DESC sd = CPU_STATE (current_cpu);
> -  host_callback *cb = STATE_CALLBACK (sd);
>  
>    if (STATE_ENVIRONMENT (sd) == OPERATING_ENVIRONMENT)
>      goto case_default;
> @@ -217,6 +216,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
>  #ifdef __linux__
>      case TRAP_LINUX_SYSCALL:
>        {
> +	host_callback *cb = STATE_CALLBACK (sd);
>  	CB_SYSCALL s;
>  	unsigned int func, arg1, arg2, arg3, arg4, arg5, arg6, arg7;
>  	int result, errcode;
> -- 
> 2.55.0
  

Patch

diff --git a/sim/m32r/traps.c b/sim/m32r/traps.c
index 7b98b2453972..bb82ae80e2aa 100644
--- a/sim/m32r/traps.c
+++ b/sim/m32r/traps.c
@@ -188,7 +188,6 @@  USI
 m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
 {
   SIM_DESC sd = CPU_STATE (current_cpu);
-  host_callback *cb = STATE_CALLBACK (sd);
 
   if (STATE_ENVIRONMENT (sd) == OPERATING_ENVIRONMENT)
     goto case_default;
@@ -217,6 +216,7 @@  m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
 #ifdef __linux__
     case TRAP_LINUX_SYSCALL:
       {
+	host_callback *cb = STATE_CALLBACK (sd);
 	CB_SYSCALL s;
 	unsigned int func, arg1, arg2, arg3, arg4, arg5, arg6, arg7;
 	int result, errcode;