From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: qemu-devel@nongnu.org, Markus Armbruster <armbru@redhat.com>,
qemu-arm@nongnu.org, qemu-block@nongnu.org,
David Gibson <david@gibson.dropbear.id.au>,
Alexander Graf <agraf@csgraf.de>
Subject: Re: [PATCH 02/11] target/arm: Clean up local variable shadowing
Date: Mon, 4 Sep 2023 16:06:26 +0200 [thread overview]
Message-ID: <d136124b-ab5e-9868-8637-6cf3edb8ca54@linaro.org> (raw)
In-Reply-To: <CAFEAcA_e+fU6JKtS+W63wr9cCJ6btu_hT_ydZWOwC0kBkDYYYQ@mail.gmail.com>
On 1/9/23 12:46, Peter Maydell wrote:
> On Thu, 31 Aug 2023 at 23:56, Philippe Mathieu-Daudé <philmd@linaro.org> wrote:
>>
>> Fix:
>>
>> target/arm/tcg/translate-m-nocp.c:509:18: error: declaration shadows a local variable [-Werror,-Wshadow]
>> TCGv_i32 tmp = load_cpu_field(v7m.fpdscr[M_REG_NS]);
>> ^
>> target/arm/tcg/translate-m-nocp.c:433:14: note: previous declaration is here
>> TCGv_i32 tmp;
>> ^
>> target/arm/tcg/mve_helper.c:2463:17: error: declaration shadows a local variable [-Werror,-Wshadow]
>> int64_t extval = sextract64(src << shift, 0, 48);
>> ^
>> target/arm/tcg/mve_helper.c:2443:18: note: previous declaration is here
>> int64_t val, extval;
>> ^
>> target/arm/hvf/hvf.c:1936:13: error: declaration shadows a local variable [-Werror,-Wshadow]
>> int ret = 0;
>> ^
>> target/arm/hvf/hvf.c:1807:9: note: previous declaration is here
>> int ret;
>> ^
>>
>> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
>> ---
>> target/arm/hvf/hvf.c | 1 -
>> target/arm/tcg/mve_helper.c | 8 ++++----
>> target/arm/tcg/translate-m-nocp.c | 2 +-
>> 3 files changed, 5 insertions(+), 6 deletions(-)
>>
>> diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c
>> index 486f90be1d..20d534faef 100644
>> --- a/target/arm/hvf/hvf.c
>> +++ b/target/arm/hvf/hvf.c
>> @@ -1933,7 +1933,6 @@ int hvf_vcpu_exec(CPUState *cpu)
>> uint32_t rt = (syndrome >> 5) & 0x1f;
>> uint32_t reg = syndrome & SYSREG_MASK;
>> uint64_t val;
>> - int ret = 0;
>>
>> if (isread) {
>> ret = hvf_sysreg_read(cpu, reg, rt);
>
> I'm not sure this is correct.
>
> The hvf_vcpu_exec() function is not documented, but in practice
> its caller expects it to return either EXCP_DEBUG (for "this was
> a guest debug exception you need to deal with") or something else
> (presumably the intention being 0 for OK).
>
> The hvf_sysreg_read() and hvf_sysreg_write() functions are also not
> documented, but they return 0 on success, or 1 for a completely
> unrecognized sysreg where we've raised the UNDEF exception (but
> not if we raised an UNDEF exception for an unrecognized GIC sysreg --
> I think this is a bug). We use this return value to decide whether
> we need to advance the PC past the insn or not. It's not the same
> as the return value we want to return from hvf_vcpu_exec().
Indeed.
> So I think the correct fix here is to retain the variable as
> locally scoped but give it a name that doesn't clash with the
> other function-scoped variable.
OK.
>> diff --git a/target/arm/tcg/mve_helper.c b/target/arm/tcg/mve_helper.c
>> index 403b345ea3..32087b6f0a 100644
>> --- a/target/arm/tcg/mve_helper.c
>> +++ b/target/arm/tcg/mve_helper.c
>> @@ -924,8 +924,8 @@ DO_1OP_IMM(vorri, DO_ORRI)
>> bool qc = false; \
>> for (e = 0; e < 16 / ESIZE; e++, mask >>= ESIZE) { \
>> bool sat = false; \
>> - TYPE r = FN(n[H##ESIZE(e)], m[H##ESIZE(e)], &sat); \
>> - mergemask(&d[H##ESIZE(e)], r, mask); \
>> + TYPE r_ = FN(n[H##ESIZE(e)], m[H##ESIZE(e)], &sat); \
>> + mergemask(&d[H##ESIZE(e)], r_, mask); \
>> qc |= sat & mask & 1; \
>> } \
>> if (qc) { \
>
> The commit message doesn't list an error message relating to
> this change and it's not immediately obvious to me what 'r'
> would be shadowing here.
Full error:
target/arm/tcg/mve_helper.c: In function ‘helper_mve_vqshlsb’:
target/arm/tcg/mve_helper.c:1259:19: warning: declaration of ‘r’ shadows
a previous local [-Wshadow=compatible-local]
1259 | typeof(N) r = FN(N, (int8_t)(M), sizeof(N) * 8, ROUND,
&su32); \
| ^
target/arm/tcg/mve_helper.c:1267:5: note: in expansion of macro
‘WRAP_QRSHL_HELPER’
1267 | WRAP_QRSHL_HELPER(do_sqrshl_bhs, N, M, false, satp)
| ^~~~~~~~~~~~~~~~~
target/arm/tcg/mve_helper.c:927:22: note: in expansion of macro
‘DO_SQSHL_OP’
927 | TYPE r = FN(n[H##ESIZE(e)], m[H##ESIZE(e)], &sat);
\
| ^~
target/arm/tcg/mve_helper.c:945:5: note: in expansion of macro ‘DO_2OP_SAT’
945 | DO_2OP_SAT(OP##b, 1, int8_t, FN) \
| ^~~~~~~~~~
target/arm/tcg/mve_helper.c:1277:1: note: in expansion of macro
‘DO_2OP_SAT_S’
1277 | DO_2OP_SAT_S(vqshls, DO_SQSHL_OP)
| ^~~~~~~~~~~~
So 'r' comes from:
#define WRAP_QRSHL_HELPER(FN, N, M, ROUND, satp) \
({ \
uint32_t su32 = 0; \
typeof(N) r = FN(N, (int8_t)(M), sizeof(N) * 8, ROUND, &su32); \
if (su32) { \
*satp = true; \
} \
r; \
})
I'll rename this one as 'qrshl_ret', and the previous one
'vqdmladh_ret'.
>> @@ -2460,7 +2460,7 @@ static inline int64_t do_sqrshl48_d(int64_t src, int64_t shift,
>> return extval;
>> }
>> } else if (shift < 48) {
>> - int64_t extval = sextract64(src << shift, 0, 48);
>> + extval = sextract64(src << shift, 0, 48);
>> if (!sat || src == (extval >> shift)) {
>> return extval;
>> }
>> @@ -2492,7 +2492,7 @@ static inline uint64_t do_uqrshl48_d(uint64_t src, int64_t shift,
>> return extval;
>> }
>> } else if (shift < 48) {
>> - uint64_t extval = extract64(src << shift, 0, 48);
>> + extval = extract64(src << shift, 0, 48);
>> if (!sat || src == (extval >> shift)) {
>> return extval;
>> }
>
> These two parts are good, but one of them is missing from the
> listed error messages in the commit message.
I'll record both.
Thanks,
Phil.
next prev parent reply other threads:[~2023-09-04 14:07 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-31 22:55 [PATCH 00/11] (few more) Steps towards enabling -Wshadow Philippe Mathieu-Daudé
2023-08-31 22:55 ` [PATCH 01/11] tcg: Clean up local variable shadowing Philippe Mathieu-Daudé
2023-09-01 0:38 ` Richard Henderson
2023-09-04 12:52 ` Philippe Mathieu-Daudé
2023-08-31 22:55 ` [PATCH 02/11] target/arm: " Philippe Mathieu-Daudé
2023-09-01 10:46 ` Peter Maydell
2023-09-04 14:06 ` Philippe Mathieu-Daudé [this message]
2023-08-31 22:55 ` [PATCH 03/11] target/mips: " Philippe Mathieu-Daudé
2023-08-31 22:55 ` [PATCH 04/11] target/m68k: " Philippe Mathieu-Daudé
2023-09-01 11:31 ` Peter Maydell
2023-08-31 22:56 ` [PATCH 05/11] hw/arm/virt: " Philippe Mathieu-Daudé
2023-09-01 11:28 ` Peter Maydell
2023-08-31 22:56 ` [PATCH 06/11] hw/arm/allwinner: " Philippe Mathieu-Daudé
2023-09-01 11:29 ` Peter Maydell
2023-08-31 22:56 ` [PATCH 07/11] hw/arm/aspeed: " Philippe Mathieu-Daudé
2023-09-01 5:47 ` Cédric Le Goater
2023-08-31 22:56 ` [PATCH 08/11] hw/m68k: " Philippe Mathieu-Daudé
2023-08-31 22:56 ` [PATCH 09/11] hw/ide/ahci: " Philippe Mathieu-Daudé
2023-08-31 22:56 ` [PATCH 10/11] net/eth: " Philippe Mathieu-Daudé
2023-09-01 7:07 ` Akihiko Odaki
2023-09-04 12:57 ` Philippe Mathieu-Daudé
2023-08-31 22:56 ` [PATCH 11/11] sysemu/device_tree: " Philippe Mathieu-Daudé
2023-09-01 8:04 ` [PATCH 00/11] (few more) Steps towards enabling -Wshadow Markus Armbruster
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d136124b-ab5e-9868-8637-6cf3edb8ca54@linaro.org \
--to=philmd@linaro.org \
--cc=agraf@csgraf.de \
--cc=armbru@redhat.com \
--cc=david@gibson.dropbear.id.au \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).