qemu-trivial
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 1/6] target/xtensa: fix uninitialized variable warning


From: Philippe Mathieu-Daudé
Subject: Re: [PATCH 1/6] target/xtensa: fix uninitialized variable warning
Date: Tue, 3 Nov 2020 03:27:53 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.3.1

On 11/3/20 2:52 AM, Chen Qun wrote:
> The compiler cannot determine whether the return values of the 
> xtensa_operand_is_register(isa, opc, opnd)
>  and xtensa_operand_is_visible(isa, opc, opnd) functions are the same.
> So,it assumes that 'rf' is not assigned, but it's used.
> 
> The compiler showed warning:
> target/xtensa/translate.c: In function ‘disas_xtensa_insn’:
> target/xtensa/translate.c:985:43: warning: ‘rf’ may be used uninitialized in 
> this function [-Wmaybe-uninitialized]
>   985 |                     arg[vopnd].num_bits = 
> xtensa_regfile_num_bits(isa, rf);
>       |                                           
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> Add a default value for 'rf' to prevented the warning.
> 
> Reported-by: Euler Robot <euler.robot@huawei.com>
> Signed-off-by: Chen Qun <kuhn.chenqun@huawei.com>
> ---
> Cc: Max Filippov <jcmvbkbc@gmail.com>
> ---
>  target/xtensa/translate.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/target/xtensa/translate.c b/target/xtensa/translate.c
> index 944a157747..eea851bbe7 100644
> --- a/target/xtensa/translate.c
> +++ b/target/xtensa/translate.c
> @@ -953,7 +953,7 @@ static void disas_xtensa_insn(CPUXtensaState *env, 
> DisasContext *dc)
>  
>          for (opnd = vopnd = 0; opnd < opnds; ++opnd) {
>              void **register_file = NULL;
> -            xtensa_regfile rf;
> +            xtensa_regfile rf = -1;

NAck (code smells).

Deferring to Max, but possible fix:

-- >8 --
@@ -953,10 +953,9 @@ static void disas_xtensa_insn(CPUXtensaState *env,
DisasContext *dc)

         for (opnd = vopnd = 0; opnd < opnds; ++opnd) {
             void **register_file = NULL;
-            xtensa_regfile rf;
+            xtensa_regfile rf = xtensa_operand_regfile(isa, opc, opnd);

             if (xtensa_operand_is_register(isa, opc, opnd)) {
-                rf = xtensa_operand_regfile(isa, opc, opnd);
                 register_file = dc->config->regfile[rf];

                 if (rf == dc->config->a_regfile) {
---



reply via email to

[Prev in Thread] Current Thread [Next in Thread]