[PATCH] tests/rcutorture: Fix build error

Cédric Le Goater posted 1 patch 3 weeks, 4 days ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20260112163350.1251114-1-clg@redhat.com
Maintainers: Paolo Bonzini <pbonzini@redhat.com>
tests/unit/rcutorture.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] tests/rcutorture: Fix build error
Posted by Cédric Le Goater 3 weeks, 4 days ago
Newer gcc compiler (version 16.0.0 20260103 (Red Hat 16.0.0-0) (GCC))
detects an unused variable error:

  ../tests/unit/rcutorture.c: In function ‘rcu_read_stress_test’:
  ../tests/unit/rcutorture.c:251:18: error: variable ‘garbage’ set but not used [-Werror=unused-but-set-variable=]
    251 |     volatile int garbage = 0;
        |                  ^~~~~~~

Since the 'garbage' variable is used to generate memory reads from the
CPU while holding the RCU lock, it can not be removed. Tag it as
((unused)) instead to silence the compiler warnings/errors.

Signed-off-by: Cédric Le Goater <clg@redhat.com>
---
 tests/unit/rcutorture.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/unit/rcutorture.c b/tests/unit/rcutorture.c
index 7662081683f5d781da74402113b73884780b1243..2f19d479a3f210cbca19205a0656eda1f4c2e5a7 100644
--- a/tests/unit/rcutorture.c
+++ b/tests/unit/rcutorture.c
@@ -248,7 +248,7 @@ static void *rcu_read_stress_test(void *arg)
     int pc;
     long long n_reads_local = 0;
     long long rcu_stress_local[RCU_STRESS_PIPE_LEN + 1] = { 0 };
-    volatile int garbage = 0;
+    volatile int garbage __attribute__ ((unused)) = 0;
 
     rcu_register_thread();
 
-- 
2.52.0


Re: [PATCH] tests/rcutorture: Fix build error
Posted by Cédric Le Goater 3 weeks, 4 days ago
On 1/12/26 17:33, Cédric Le Goater wrote:
> Newer gcc compiler (version 16.0.0 20260103 (Red Hat 16.0.0-0) (GCC))
> detects an unused variable error:
> 
>    ../tests/unit/rcutorture.c: In function ‘rcu_read_stress_test’:
>    ../tests/unit/rcutorture.c:251:18: error: variable ‘garbage’ set but not used [-Werror=unused-but-set-variable=]
>      251 |     volatile int garbage = 0;
>          |                  ^~~~~~~
> 
> Since the 'garbage' variable is used to generate memory reads from the
> CPU while holding the RCU lock, it can not be removed. Tag it as
> ((unused)) instead to silence the compiler warnings/errors.
> 
> Signed-off-by: Cédric Le Goater <clg@redhat.com>
> ---
>   tests/unit/rcutorture.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tests/unit/rcutorture.c b/tests/unit/rcutorture.c
> index 7662081683f5d781da74402113b73884780b1243..2f19d479a3f210cbca19205a0656eda1f4c2e5a7 100644
> --- a/tests/unit/rcutorture.c
> +++ b/tests/unit/rcutorture.c
> @@ -248,7 +248,7 @@ static void *rcu_read_stress_test(void *arg)
>       int pc;
>       long long n_reads_local = 0;
>       long long rcu_stress_local[RCU_STRESS_PIPE_LEN + 1] = { 0 };
> -    volatile int garbage = 0;
> +    volatile int garbage __attribute__ ((unused)) = 0;
>   
>       rcu_register_thread();
>   

Applied to vfio-next.

Thanks,

C.


Re: [PATCH] tests/rcutorture: Fix build error
Posted by Richard Henderson 3 weeks, 4 days ago
On 1/13/26 03:33, Cédric Le Goater wrote:
> Newer gcc compiler (version 16.0.0 20260103 (Red Hat 16.0.0-0) (GCC))
> detects an unused variable error:
> 
>    ../tests/unit/rcutorture.c: In function ‘rcu_read_stress_test’:
>    ../tests/unit/rcutorture.c:251:18: error: variable ‘garbage’ set but not used [-Werror=unused-but-set-variable=]
>      251 |     volatile int garbage = 0;
>          |                  ^~~~~~~
> 
> Since the 'garbage' variable is used to generate memory reads from the
> CPU while holding the RCU lock, it can not be removed. Tag it as
> ((unused)) instead to silence the compiler warnings/errors.

That shouldn't happen for a volatile variable: please report this as a compiler bug.

That said, gcc-16 has been released, so
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


r~

> 
> Signed-off-by: Cédric Le Goater <clg@redhat.com>
> ---
>   tests/unit/rcutorture.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tests/unit/rcutorture.c b/tests/unit/rcutorture.c
> index 7662081683f5d781da74402113b73884780b1243..2f19d479a3f210cbca19205a0656eda1f4c2e5a7 100644
> --- a/tests/unit/rcutorture.c
> +++ b/tests/unit/rcutorture.c
> @@ -248,7 +248,7 @@ static void *rcu_read_stress_test(void *arg)
>       int pc;
>       long long n_reads_local = 0;
>       long long rcu_stress_local[RCU_STRESS_PIPE_LEN + 1] = { 0 };
> -    volatile int garbage = 0;
> +    volatile int garbage __attribute__ ((unused)) = 0;
>   
>       rcu_register_thread();
>   


Re: [PATCH] tests/rcutorture: Fix build error
Posted by Cédric Le Goater 3 weeks, 4 days ago
On 1/12/26 22:58, Richard Henderson wrote:
> On 1/13/26 03:33, Cédric Le Goater wrote:
>> Newer gcc compiler (version 16.0.0 20260103 (Red Hat 16.0.0-0) (GCC))
>> detects an unused variable error:
>>
>>    ../tests/unit/rcutorture.c: In function ‘rcu_read_stress_test’:
>>    ../tests/unit/rcutorture.c:251:18: error: variable ‘garbage’ set but not used [-Werror=unused-but-set-variable=]
>>      251 |     volatile int garbage = 0;
>>          |                  ^~~~~~~
>>
>> Since the 'garbage' variable is used to generate memory reads from the
>> CPU while holding the RCU lock, it can not be removed. Tag it as
>> ((unused)) instead to silence the compiler warnings/errors.
> 
> That shouldn't happen for a volatile variable: please report this as a compiler bug.

Yes. That seemed to defeat the purpose.

> 
> That said, gcc-16 has been released, so
> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

Applied to vfio-next.

Thanks,

C.

> 
> 
> r~
> 
>>
>> Signed-off-by: Cédric Le Goater <clg@redhat.com>
>> ---
>>   tests/unit/rcutorture.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/tests/unit/rcutorture.c b/tests/unit/rcutorture.c
>> index 7662081683f5d781da74402113b73884780b1243..2f19d479a3f210cbca19205a0656eda1f4c2e5a7 100644
>> --- a/tests/unit/rcutorture.c
>> +++ b/tests/unit/rcutorture.c
>> @@ -248,7 +248,7 @@ static void *rcu_read_stress_test(void *arg)
>>       int pc;
>>       long long n_reads_local = 0;
>>       long long rcu_stress_local[RCU_STRESS_PIPE_LEN + 1] = { 0 };
>> -    volatile int garbage = 0;
>> +    volatile int garbage __attribute__ ((unused)) = 0;
>>       rcu_register_thread();
>