diff mbox series

[4/4] target/ppc: fix warning with clang-15

Message ID 20230213161352.17199-5-pierrick.bouvier@linaro.org
State New
Headers show
Series Adds support for running QEMU natively on windows-arm64 | expand

Commit Message

Pierrick Bouvier Feb. 13, 2023, 4:13 p.m. UTC
When compiling for windows-arm64 using clang-15, it reports a sometimes
uninitialized variable. This seems to be a false positive, as a default
case guards switch expressions, preventing to return an uninitialized
value, but clang seems unhappy with assert definition.

Setting the rnd variable to zero does not hurt anyway.

../target/ppc/dfp_helper.c:141:13: error: variable 'rnd' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]                                                                              assert(0); /* cannot get here */                                                                                                                                                                                    ^~~~~~~~~
../include/qemu/osdep.h:229:20: note: expanded from macro 'assert'                                                                                                                                        #define assert(x)  g_assert(x)                                                                                                                                                                                                         ^~~~~~~~~~~
/clangarm64/bin/../include/glib-2.0/glib/gtestutils.h:235:49: note: expanded from macro 'g_assert'                                                                                                                               if G_LIKELY (expr) ; else \
                                                ^~~~~~~~~~~~~~~
/clangarm64/bin/../include/glib-2.0/glib/gmacros.h:1186:25: note: expanded from macro 'G_LIKELY'
                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../target/ppc/dfp_helper.c:144:42: note: uninitialized use occurs here
    decContextSetRounding(&dfp->context, rnd);

Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
---
 target/ppc/dfp_helper.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Philippe Mathieu-Daudé Feb. 14, 2023, 7:14 a.m. UTC | #1
On 13/2/23 17:13, Pierrick Bouvier wrote:
> When compiling for windows-arm64 using clang-15, it reports a sometimes
> uninitialized variable. This seems to be a false positive, as a default
> case guards switch expressions, preventing to return an uninitialized
> value, but clang seems unhappy with assert definition.
> 
> Setting the rnd variable to zero does not hurt anyway.
> 
> ../target/ppc/dfp_helper.c:141:13: error: variable 'rnd' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]                                                                              assert(0); /* cannot get here */                                                                                                                                                                                    ^~~~~~~~~
> ../include/qemu/osdep.h:229:20: note: expanded from macro 'assert'                                                                                                                                        #define assert(x)  g_assert(x)                                                                                                                                                                                                         ^~~~~~~~~~~
> /clangarm64/bin/../include/glib-2.0/glib/gtestutils.h:235:49: note: expanded from macro 'g_assert'                                                                                                                               if G_LIKELY (expr) ; else \
>                                                  ^~~~~~~~~~~~~~~
> /clangarm64/bin/../include/glib-2.0/glib/gmacros.h:1186:25: note: expanded from macro 'G_LIKELY'
>                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> ../target/ppc/dfp_helper.c:144:42: note: uninitialized use occurs here
>      decContextSetRounding(&dfp->context, rnd);
> 
> Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
> ---
>   target/ppc/dfp_helper.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/target/ppc/dfp_helper.c b/target/ppc/dfp_helper.c
> index cc024316d5..0b4b280683 100644
> --- a/target/ppc/dfp_helper.c
> +++ b/target/ppc/dfp_helper.c
> @@ -69,7 +69,7 @@ struct PPC_DFP {
>   
>   static void dfp_prepare_rounding_mode(decContext *context, uint64_t fpscr)
>   {
> -    enum rounding rnd;
> +    enum rounding rnd = 0;
>   
>       switch ((fpscr & FP_DRN) >> FPSCR_DRN0) {
>       case 0:
> @@ -106,7 +106,7 @@ static void dfp_prepare_rounding_mode(decContext *context, uint64_t fpscr)
>   static void dfp_set_round_mode_from_immediate(uint8_t r, uint8_t rmc,
>                                                     struct PPC_DFP *dfp)
>   {
> -    enum rounding rnd;
> +    enum rounding rnd = 0;

Could DEC_ROUND_DEFAULT be clearer?
Pierrick Bouvier Feb. 14, 2023, 7:57 a.m. UTC | #2
On 2/14/23 08:14, Philippe Mathieu-Daudé wrote:
> On 13/2/23 17:13, Pierrick Bouvier wrote:
>> When compiling for windows-arm64 using clang-15, it reports a sometimes
>> uninitialized variable. This seems to be a false positive, as a default
>> case guards switch expressions, preventing to return an uninitialized
>> value, but clang seems unhappy with assert definition.
>>
>> Setting the rnd variable to zero does not hurt anyway.
>>
>> ../target/ppc/dfp_helper.c:141:13: error: variable 'rnd' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]                                                                              assert(0); /* cannot get here */                                                                                                                                                                                    ^~~~~~~~~
>> ../include/qemu/osdep.h:229:20: note: expanded from macro 'assert'                                                                                                                                        #define assert(x)  g_assert(x)                                                                                                                                                                                                         ^~~~~~~~~~~
>> /clangarm64/bin/../include/glib-2.0/glib/gtestutils.h:235:49: note: expanded from macro 'g_assert'                                                                                                                               if G_LIKELY (expr) ; else \
>>                                                   ^~~~~~~~~~~~~~~
>> /clangarm64/bin/../include/glib-2.0/glib/gmacros.h:1186:25: note: expanded from macro 'G_LIKELY'
>>                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> ../target/ppc/dfp_helper.c:144:42: note: uninitialized use occurs here
>>       decContextSetRounding(&dfp->context, rnd);
>>
>> Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
>> ---
>>    target/ppc/dfp_helper.c | 4 ++--
>>    1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/target/ppc/dfp_helper.c b/target/ppc/dfp_helper.c
>> index cc024316d5..0b4b280683 100644
>> --- a/target/ppc/dfp_helper.c
>> +++ b/target/ppc/dfp_helper.c
>> @@ -69,7 +69,7 @@ struct PPC_DFP {
>>    
>>    static void dfp_prepare_rounding_mode(decContext *context, uint64_t fpscr)
>>    {
>> -    enum rounding rnd;
>> +    enum rounding rnd = 0;
>>    
>>        switch ((fpscr & FP_DRN) >> FPSCR_DRN0) {
>>        case 0:
>> @@ -106,7 +106,7 @@ static void dfp_prepare_rounding_mode(decContext *context, uint64_t fpscr)
>>    static void dfp_set_round_mode_from_immediate(uint8_t r, uint8_t rmc,
>>                                                      struct PPC_DFP *dfp)
>>    {
>> -    enum rounding rnd;
>> +    enum rounding rnd = 0;
> 
> Could DEC_ROUND_DEFAULT be clearer?
> 

I missed that macro definition, and that seems like a good default 
value. I'll change to this.
Richard Henderson Feb. 14, 2023, 6:10 p.m. UTC | #3
On 2/13/23 06:13, Pierrick Bouvier wrote:
> When compiling for windows-arm64 using clang-15, it reports a sometimes
> uninitialized variable. This seems to be a false positive, as a default
> case guards switch expressions, preventing to return an uninitialized
> value, but clang seems unhappy with assert definition.
> 
> Setting the rnd variable to zero does not hurt anyway.
> 
> ../target/ppc/dfp_helper.c:141:13: error: variable 'rnd' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]                                                                              assert(0); /* cannot get here */                                                                                                                                                                                    ^~~~~~~~~
> ../include/qemu/osdep.h:229:20: note: expanded from macro 'assert'                                                                                                                                        #define assert(x)  g_assert(x)                                                                                                                                                                                                         ^~~~~~~~~~~
> /clangarm64/bin/../include/glib-2.0/glib/gtestutils.h:235:49: note: expanded from macro 'g_assert'                                                                                                                               if G_LIKELY (expr) ; else \
>                                                  ^~~~~~~~~~~~~~~
> /clangarm64/bin/../include/glib-2.0/glib/gmacros.h:1186:25: note: expanded from macro 'G_LIKELY'
>                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> ../target/ppc/dfp_helper.c:144:42: note: uninitialized use occurs here
>      decContextSetRounding(&dfp->context, rnd);

I think the problem is with assert(0) not being seen to terminate.
Replace these with g_assert_not_reached().


r~
Pierrick Bouvier Feb. 15, 2023, 10:58 a.m. UTC | #4
On 2/14/23 19:10, Richard Henderson wrote:
> On 2/13/23 06:13, Pierrick Bouvier wrote:
>> When compiling for windows-arm64 using clang-15, it reports a sometimes
>> uninitialized variable. This seems to be a false positive, as a default
>> case guards switch expressions, preventing to return an uninitialized
>> value, but clang seems unhappy with assert definition.
>>
>> Setting the rnd variable to zero does not hurt anyway.
>>
>> ../target/ppc/dfp_helper.c:141:13: error: variable 'rnd' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]                                                                              assert(0); /* cannot get here */                                                                                                                                                                                    ^~~~~~~~~
>> ../include/qemu/osdep.h:229:20: note: expanded from macro 'assert'                                                                                                                                        #define assert(x)  g_assert(x)                                                                                                                                                                                                         ^~~~~~~~~~~
>> /clangarm64/bin/../include/glib-2.0/glib/gtestutils.h:235:49: note: expanded from macro 'g_assert'                                                                                                                               if G_LIKELY (expr) ; else \
>>                                                   ^~~~~~~~~~~~~~~
>> /clangarm64/bin/../include/glib-2.0/glib/gmacros.h:1186:25: note: expanded from macro 'G_LIKELY'
>>                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> ../target/ppc/dfp_helper.c:144:42: note: uninitialized use occurs here
>>       decContextSetRounding(&dfp->context, rnd);
> 
> I think the problem is with assert(0) not being seen to terminate.
> Replace these with g_assert_not_reached().
> 

Indeed, that solves the issue. Thanks for the suggestion, I'll use this 
instead.

> 
> r~
>
diff mbox series

Patch

diff --git a/target/ppc/dfp_helper.c b/target/ppc/dfp_helper.c
index cc024316d5..0b4b280683 100644
--- a/target/ppc/dfp_helper.c
+++ b/target/ppc/dfp_helper.c
@@ -69,7 +69,7 @@  struct PPC_DFP {
 
 static void dfp_prepare_rounding_mode(decContext *context, uint64_t fpscr)
 {
-    enum rounding rnd;
+    enum rounding rnd = 0;
 
     switch ((fpscr & FP_DRN) >> FPSCR_DRN0) {
     case 0:
@@ -106,7 +106,7 @@  static void dfp_prepare_rounding_mode(decContext *context, uint64_t fpscr)
 static void dfp_set_round_mode_from_immediate(uint8_t r, uint8_t rmc,
                                                   struct PPC_DFP *dfp)
 {
-    enum rounding rnd;
+    enum rounding rnd = 0;
     if (r == 0) {
         switch (rmc & 3) {
         case 0: