arm: fix some -Wshadow warnings
cover arm: fix some -Wshadow warnings
These patches fix some -Wshadow warnings in arm related code.
-- PMM
Peter Maydell (4):
hw/intc/arm_gicv3_its: Avoid shadowing variable in
do_process_its_cmd()
hw/misc/arm_sysctl.c: Avoid shadowing local variable hw/arm/smmuv3.c: Avoid shadowing variable hw/arm/smmuv3-internal.h: Don't use locals in statement macros
hw/arm/smmuv3-internal.h | 41 +++++++++++++--------------------------- hw/arm/smmuv3.c | 4 ++-- hw/intc/arm_gicv3_its.c | 6 +++--- hw/misc/arm_sysctl.c | 6 +++--- 4 files changed, 21 insertions(+), 36 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/4 hw/intc/arm_gicv3_its: Avoid shadowing variable in do_process_its_cmd()
Avoid shadowing a local variable in do_process_its_cmd():
../../hw/intc/arm_gicv3_its.c:548:17: warning: declaration of ‘ite’ shadows a previous local [-Wshadow=compatible-local]
548 | ITEntry ite = {};
| ^~~../../hw/intc/arm_gicv3_its.c:518:13: note: shadowed declaration is here
518 | ITEntry ite;
| ^~~
--- hw/intc/arm_gicv3_its.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
hw/intc/arm_gicv3_its.c +3 -3
@@ -545,10 +545,10 @@ static ItsCmdResult do_process_its_cmd(GICv3ITSState *s, uint32_t devid, }if (cmdres ==CMD_CONTINUE_OK && cmd ==DISCARD ) { -ITEntry ite = {}; +ITEntry i = {};/* remove mapping from interrupt translation table */ - ite.valid = false; -return update_ite (s, eventid, &dte, &ite) ?CMD_CONTINUE_OK :CMD_STALL ; + i.valid = false; +return update_ite (s, eventid, &dte, &i) ?CMD_CONTINUE_OK :CMD_STALL ; }return CMD_CONTINUE_OK ; }
Signature · 1 line
2.34.1
Re: [PATCH 1/4] hw/intc/arm_gicv3_its: Avoid shadowing variable in do_process_its_cmd()
Quoted 9 lines · Peter Maydell
Avoid shadowing a local variable in
do_process_its_cmd():
../../hw/intc/arm_gicv3_its.c:548:17: warning: declaration of ‘ite’ shadows a previous local [-Wshadow=compatible-local]
548 | ITEntry ite = {};
| ^~~../../hw/intc/arm_gicv3_its.c:518:13: note: shadowed declaration is here
518 | ITEntry ite;
| ^~~
Quoted 4 lines
Signed-off-by Peter Maydell <[email protected]>--- hw/intc/arm_gicv3_its.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
Re: [PATCH 1/4] hw/intc/arm_gicv3_its: Avoid shadowing variable in do_process_its_cmd()
In reply to Peter MaydellQuoted 22 lines · Peter Maydell
Avoid shadowing a local variable in
do_process_its_cmd():
../../hw/intc/arm_gicv3_its.c:548:17: warning: declaration of ‘ite’ shadows a previous local [-Wshadow=compatible-local]
548 | ITEntry ite = {};
| ^~~../../hw/intc/arm_gicv3_its.c:518:13: note: shadowed declaration is here
518 | ITEntry ite;
| ^~~Signed-off-by Peter Maydell <[email protected]>--- hw/intc/arm_gicv3_its.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)hw/intc/arm_gicv3_its.c +0
-0@@ -545,10 +545,10 @@ static ItsCmdResult do_process_its_cmd(GICv3ITSState *s, uint32_t devid, }if (cmdres ==CMD_CONTINUE_OK && cmd ==DISCARD ) {
hw/intc/arm_gicv3_its.c static ItsCmdResult do_process_its_cmd(GICv3ITSState *s, uint32_t devid, · line 554
Quoted 10 lines
hw/intc/arm_gicv3_its.c +3
-3-ITEntry ite = {}; +ITEntry i = {};/* remove mapping from interrupt translation table */ - ite.valid = false; -return update_ite (s, eventid, &dte, &ite) ?CMD_CONTINUE_OK :CMD_STALL ; + i.valid = false; +return update_ite (s, eventid, &dte, &i) ?CMD_CONTINUE_OK :CMD_STALL ; }return CMD_CONTINUE_OK ; }
Eric
PATCH 2/4 hw/misc/arm_sysctl.c: Avoid shadowing local variable
In reply to Peter MaydellAvoid shadowing a local variable in arm_sysctl_write():
../../hw/misc/arm_sysctl.c: In function ‘arm_sysctl_write’:../../hw/misc/arm_sysctl.c:537:26: warning: declaration of ‘val’ shadows a parameter [-Wshadow=local]
537 | uint32_t val;
| ^~~../../hw/misc/arm_sysctl.c:388:39: note: shadowed declaration is here
388 | uint64_t val, unsigned size)
| ~~~~~~~~~^~~--- hw/misc/arm_sysctl.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
hw/misc/arm_sysctl.c +3 -3
@@ -534,12 +534,12 @@ static void arm_sysctl_write(void *opaque, hwaddr offset, s->sys_cfgstat |=2 ;/* error */ } }else { -uint32_t val; +uint32_t data;if (!vexpress_cfgctrl_read (s, dcc, function, site, position, - device, &val)) { + device, &data)) { s->sys_cfgstat |=2 ;/* error */ }else { - s->sys_cfgdata = val; + s->sys_cfgdata = data; } } }
Signature · 1 line
2.34.1
Re: [PATCH 2/4] hw/misc/arm_sysctl.c: Avoid shadowing local variable
Quoted 7 lines · Peter Maydell
Avoid shadowing a local variable in
arm_sysctl_write():
../../hw/misc/arm_sysctl.c: In function ‘arm_sysctl_write’:../../hw/misc/arm_sysctl.c:537:26: warning: declaration of ‘val’ shadows a parameter [-Wshadow=local]
537 |uint32_tval;
| ^~~../../hw/misc/arm_sysctl.c:388:39: note: shadowed declaration is here
Quoted 7 lines
388 | uint64_t val, unsigned size) | ~~~~~~~~~^~~Signed-off-by Peter Maydell <[email protected]>--- hw/misc/arm_sysctl.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
Re: [PATCH 2/4] hw/misc/arm_sysctl.c: Avoid shadowing local variable
In reply to Peter MaydellQuoted 25 lines · Peter Maydell
Avoid shadowing a local variable in
arm_sysctl_write():
../../hw/misc/arm_sysctl.c: In function ‘arm_sysctl_write’:../../hw/misc/arm_sysctl.c:537:26: warning: declaration of ‘val’ shadows a parameter [-Wshadow=local]
537 |uint32_tval;
| ^~~../../hw/misc/arm_sysctl.c:388:39: note: shadowed declaration is here388 | uint64_t val, unsigned size) | ~~~~~~~~~^~~Signed-off-by Peter Maydell <[email protected]>--- hw/misc/arm_sysctl.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)hw/misc/arm_sysctl.c +1
-1@@ -534,12 +534,12 @@ static void arm_sysctl_write(void *opaque, hwaddr offset, s->sys_cfgstat |=2 ;/* error */ } }else { -uint32_t val; +uint32_t data;
hw/misc/arm_sysctl.c static void arm_sysctl_write(void *opaque, hwaddr offset, · line 545
Quoted 10 lines
hw/misc/arm_sysctl.c +2
-2if (!vexpress_cfgctrl_read (s, dcc, function, site, position, - device, &val)) { + device, &data)) { s->sys_cfgstat |=2 ;/* error */ }else { - s->sys_cfgdata = val; + s->sys_cfgdata = data; } } }
Eric
PATCH 3/4 hw/arm/smmuv3.c: Avoid shadowing variable
In reply to Peter MaydellAvoid shadowing a variable in smmuv3_notify_iova():
../../hw/arm/smmuv3.c: In function ‘smmuv3_notify_iova’:../../hw/arm/smmuv3.c:1043:23: warning: declaration of ‘event’ shadows a previous local [-Wshadow=local]
1043 | SMMUEventInfo event = {.inval_ste_allowed = true};
| ^~~~~../../hw/arm/smmuv3.c:1038:19: note: shadowed declaration is here
1038 | IOMMUTLBEvent event;
| ^~~~~
--- hw/arm/smmuv3.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
hw/arm/smmuv3.c +2 -2
@@ -1040,8 +1040,8 @@ static void smmuv3_notify_iova(IOMMUMemoryRegion *mr,SMMUv3State *s = sdev->smmu;if (!tg) { -SMMUEventInfo event = {.inval_ste_allowed = true}; -SMMUTransCfg *cfg =smmuv3_get_config (sdev, &event); +SMMUEventInfo eventinfo = {.inval_ste_allowed = true}; +SMMUTransCfg *cfg =smmuv3_get_config (sdev, &eventinfo);SMMUTransTableInfo *tt;if (!cfg) {
Signature · 1 line
2.34.1
Re: [PATCH 3/4] hw/arm/smmuv3.c: Avoid shadowing variable
Quoted 10 lines · Peter Maydell
Avoid shadowing a variable in
smmuv3_notify_iova():
../../hw/arm/smmuv3.c: In function ‘smmuv3_notify_iova’:../../hw/arm/smmuv3.c:1043:23: warning: declaration of ‘event’ shadows a previous local [-Wshadow=local]
1043 | SMMUEventInfo event = {.inval_ste_allowed = true};
| ^~~~~../../hw/arm/smmuv3.c:1038:19: note: shadowed declaration is here
1038 | IOMMUTLBEvent event;
| ^~~~~
Quoted 4 lines
Signed-off-by Peter Maydell <[email protected]>--- hw/arm/smmuv3.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Re: [PATCH 3/4] hw/arm/smmuv3.c: Avoid shadowing variable
In reply to Peter MaydellHi Peter,
Quoted 20 lines · Peter Maydell
Avoid shadowing a variable in
smmuv3_notify_iova():
../../hw/arm/smmuv3.c: In function ‘smmuv3_notify_iova’:../../hw/arm/smmuv3.c:1043:23: warning: declaration of ‘event’ shadows a previous local [-Wshadow=local]
1043 | SMMUEventInfo event = {.inval_ste_allowed = true};
| ^~~~~../../hw/arm/smmuv3.c:1038:19: note: shadowed declaration is here
1038 | IOMMUTLBEvent event;
| ^~~~~Signed-off-by Peter Maydell <[email protected]>--- hw/arm/smmuv3.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)hw/arm/smmuv3.c +0
-0
hw/arm/smmuv3.c static void smmuv3_notify_iova(IOMMUMemoryRegion *mr, · line 1047
Quoted 10 lines
hw/arm/smmuv3.c +2
-2@@ -1040,8 +1040,8 @@ static void smmuv3_notify_iova(IOMMUMemoryRegion *mr,SMMUv3State *s = sdev->smmu;if (!tg) { -SMMUEventInfo event = {.inval_ste_allowed = true}; -SMMUTransCfg *cfg =smmuv3_get_config (sdev, &event); +SMMUEventInfo eventinfo = {.inval_ste_allowed = true}; +SMMUTransCfg *cfg =smmuv3_get_config (sdev, &eventinfo);SMMUTransTableInfo *tt;if (!cfg) {
Thanks!
Eric
PATCH 4/4 hw/arm/smmuv3-internal.h: Don't use locals in statement macros
In reply to Peter MaydellThe STE_CTXPTR() and STE_S2TTB() macros both extract two halves of an address from fields in the STE and combine them into a single value to return. The current code for this uses a GCC statement expression. There are two problems with this:
(1) The type chosen for the variable in the statement expr is 'unsigned long', which might not be 64 bits
(2) the name chosen for the variable causes -Wshadow warnings because it's the same as a variable in use at the callsite:
In file included from ../../hw/arm/smmuv3.c:34:../../hw/arm/smmuv3.c: In function ‘smmu_get_cd’:../../hw/arm/smmuv3-internal.h:538:23: warning: declaration of ‘addr’ shadows a previous local [-Wshadow=compatible-local]
538 | unsigned long addr; \
| ^~~~../../hw/arm/smmuv3.c:339:23: note: in expansion of macro ‘STE_CTXPTR’
339 | dma_addr_t addr = STE_CTXPTR(ste);
| ^~~~~~~~~~../../hw/arm/smmuv3.c:339:16: note: shadowed declaration is here
339 | dma_addr_t addr = STE_CTXPTR(ste);
| ^~~~
Sidestep both of these problems by just using a single expression rather than a statement expr.
For CMD_ADDR, we got the type of the variable right but still run into -Wshadow problems:
In file included from ../../hw/arm/smmuv3.c:34:../../hw/arm/smmuv3.c: In function ‘smmuv3_range_inval’:../../hw/arm/smmuv3-internal.h:334:22: warning: declaration of ‘addr’ shadows a previous local [-Wshadow=compatible-local]
334 | uint64_t addr = high << 32 | (low << 12); \
| ^~~~../../hw/arm/smmuv3.c:1104:28: note: in expansion of macro ‘CMD_ADDR’
1104 | dma_addr_t end, addr = CMD_ADDR(cmd);
| ^~~~~~~~../../hw/arm/smmuv3.c:1104:21: note: shadowed declaration is here
1104 | dma_addr_t end, addr = CMD_ADDR(cmd);
| ^~~~
so convert it too.
CD_TTB has neither problem, but it is the only other macro in the file that uses this pattern, so we convert it also for consistency's sake.
We use extract64() rather than extract32() to avoid having to explicitly cast the result to uint64_t.
--- hw/arm/smmuv3-internal.h | 41 +++++++++++++--------------------------- 1 file changed, 13 insertions(+), 28 deletions(-)
hw/arm/smmuv3-internal.h +13 -28
@@ -328,12 +328,9 @@ enum { /* Command completion notification */#define CMD_TTL (x) extract32((x)->word[2], 8 , 2)#define CMD_TG (x) extract32((x)->word[2], 10, 2)#define CMD_STE_RANGE (x) extract32((x)->word[2], 0 , 5) -#define CMD_ADDR (x) ({ \ - uint64_t high = (uint64_t)(x)->word[3]; \ - uint64_t low = extract32((x)->word[2], 12, 20); \ - uint64_t addr = high << 32 | (low << 12); \ - addr; \ - }) +#define CMD_ADDR (x) \ + (((uint64_t)((x)->word[3]) << 32) | \ + ((extract64((x)->word[2], 12, 20)) << 12))#define SMMU_FEATURE_2LVL_STE (1 << 0)
@@ -533,21 +530,13 @@ typedef struct CD {#define STE_S2S (x) extract32((x)->word[5], 25, 1)#define STE_S2R (x) extract32((x)->word[5], 26, 1) -#define STE_CTXPTR (x) \ - ({ \ - unsigned long addr; \ - addr = (uint64_t)extract32((x)->word[1], 0, 16) << 32; \ - addr |= (uint64_t)((x)->word[0] & 0xffffffc0); \ - addr; \ - }) +#define STE_CTXPTR (x) \ + ((extract64((x)->word[1], 0, 16) << 32) | \ + ((x)->word[0] & 0xffffffc0)) -#define STE_S2TTB (x) \ - ({ \ - unsigned long addr; \ - addr = (uint64_t)extract32((x)->word[7], 0, 16) << 32; \ - addr |= (uint64_t)((x)->word[6] & 0xfffffff0); \ - addr; \ - }) +#define STE_S2TTB (x) \ + ((extract64((x)->word[7], 0, 16) << 32) | \ + ((x)->word[6] & 0xfffffff0))static inline int oas2bits (int oas_field) {
@@ -585,14 +574,10 @@ static inline int pa_range(STE *ste)#define CD_VALID (x) extract32((x)->word[0], 31, 1)#define CD_ASID (x) extract32((x)->word[1], 16, 16) -#define CD_TTB (x, sel) \ - ({ \ - uint64_t hi, lo; \ - hi = extract32((x)->word[(sel) * 2 + 3], 0, 19); \ - hi <<= 32; \ - lo = (x)->word[(sel) * 2 + 2] & ~0xfULL; \ - hi | lo; \ - }) +#define CD_TTB (x, sel) \ + ((extract64((x)->word[(sel) * 2 + 3], 0, 19) << 32) | \ + ((x)->word[(sel) * 2 + 2] & ~0xfULL)) +#define CD_HAD (x, sel) extract32((x)->word[(sel) * 2 + 2], 1, 1)#define CD_TSZ (x, sel) extract32((x)->word[0], (16 * (sel)) + 0, 6)
Signature · 1 line
2.34.1
Re: [PATCH 4/4] hw/arm/smmuv3-internal.h: Don't use locals in statement macros
Hi Peter,
Quoted 112 lines · Peter Maydell
The
STE_CTXPTR()andSTE_S2TTB()macros both extract two halves of an address from fields in the STE and combine them into a single value to return. The current code for this uses a GCC statement expression. There are two problems with this:(1) The type chosen for the variable in the statement expr is 'unsigned long', which might not be 64 bits
(2) the name chosen for the variable causes -Wshadow warnings because it's the same as a variable in use at the callsite:
In file included from
../../hw/arm/smmuv3.c:34:../../hw/arm/smmuv3.c: In function ‘smmu_get_cd’:../../hw/arm/smmuv3-internal.h:538:23: warning: declaration of ‘addr’ shadows a previous local [-Wshadow=compatible-local]
538 | unsigned long addr; \
| ^~~~../../hw/arm/smmuv3.c:339:23: note: in expansion of macro ‘STE_CTXPTR’339 | dma_addr_t addr = STE_CTXPTR(ste); | ^~~~~~~~~~
../../hw/arm/smmuv3.c:339:16: note: shadowed declaration is here
339 |dma_addr_taddr =STE_CTXPTR(ste);
| ^~~~Sidestep both of these problems by just using a single expression rather than a statement expr.
For
CMD_ADDR, we got the type of the variable right but still run into -Wshadow problems:In file included from
../../hw/arm/smmuv3.c:34:../../hw/arm/smmuv3.c: In function ‘smmuv3_range_inval’:../../hw/arm/smmuv3-internal.h:334:22: warning: declaration of ‘addr’ shadows a previous local [-Wshadow=compatible-local]
334 |uint64_taddr = high << 32 | (low << 12); \
| ^~~~../../hw/arm/smmuv3.c:1104:28: note: in expansion of macro ‘CMD_ADDR’
1104 |dma_addr_tend, addr =CMD_ADDR(cmd);
| ^~~~~~~~../../hw/arm/smmuv3.c:1104:21: note: shadowed declaration is here
1104 |dma_addr_tend, addr =CMD_ADDR(cmd);
| ^~~~so convert it too.
CD_TTBhas neither problem, but it is the only other macro in the file that uses this pattern, so we convert it also for consistency's sake.We use
extract64()rather thanextract32()to avoid having to explicitly cast the result touint64_t.Signed-off-by Peter Maydell <[email protected]>--- hw/arm/smmuv3-internal.h | 41 +++++++++++++--------------------------- 1 file changed, 13 insertions(+), 28 deletions(-)hw/arm/smmuv3-internal.h +9
-25@@ -328,12 +328,9 @@ enum { /* Command completion notification */#define CMD_TTL (x) extract32((x)->word[2], 8 , 2)#define CMD_TG (x) extract32((x)->word[2], 10, 2)#define CMD_STE_RANGE (x) extract32((x)->word[2], 0 , 5) -#define CMD_ADDR (x) ({ \ - uint64_t high = (uint64_t)(x)->word[3]; \ - uint64_t low = extract32((x)->word[2], 12, 20); \ - uint64_t addr = high << 32 | (low << 12); \ - addr; \ - }) +#define CMD_ADDR (x) \ + (((uint64_t)((x)->word[3]) << 32) | \ + ((extract64((x)->word[2], 12, 20)) << 12))#define SMMU_FEATURE_2LVL_STE (1 << 0)@@ -533,21 +530,13 @@ typedef struct CD {#define STE_S2S (x) extract32((x)->word[5], 25, 1)#define STE_S2R (x) extract32((x)->word[5], 26, 1) -#define STE_CTXPTR (x) \ - ({ \ - unsigned long addr; \ - addr = (uint64_t)extract32((x)->word[1], 0, 16) << 32; \ - addr |= (uint64_t)((x)->word[0] & 0xffffffc0); \ - addr; \ - }) +#define STE_CTXPTR (x) \ + ((extract64((x)->word[1], 0, 16) << 32) | \ + ((x)->word[0] & 0xffffffc0)) -#define STE_S2TTB (x) \ - ({ \ - unsigned long addr; \ - addr = (uint64_t)extract32((x)->word[7], 0, 16) << 32; \ - addr |= (uint64_t)((x)->word[6] & 0xfffffff0); \ - addr; \ - }) +#define STE_S2TTB (x) \ + ((extract64((x)->word[7], 0, 16) << 32) | \ + ((x)->word[6] & 0xfffffff0))static inline int oas2bits (int oas_field) {@@ -585,14 +574,10 @@ static inline int pa_range(STE *ste)#define CD_VALID (x) extract32((x)->word[0], 31, 1)#define CD_ASID (x) extract32((x)->word[1], 16, 16) -#define CD_TTB (x, sel) \ - ({ \ - uint64_t hi, lo; \ - hi = extract32((x)->word[(sel) * 2 + 3], 0, 19); \ - hi <<= 32; \
hw/arm/smmuv3-internal.h static inline int pa_range(STE *ste) · line 583
Quoted 10 lines
hw/arm/smmuv3-internal.h +4
-3- lo = (x)->word[(sel) *2 +2 ] & ~0xfULL ; \ - hi | lo; \ - }) +#define CD_TTB (x, sel) \ + ((extract64((x)->word[(sel) * 2 + 3], 0, 19) << 32) | \ + ((x)->word[(sel) * 2 + 2] & ~0xfULL)) +#define CD_HAD (x, sel) extract32((x)->word[(sel) * 2 + 2], 1, 1)#define CD_TSZ (x, sel) extract32((x)->word[0], (16 * (sel)) + 0, 6)
Eric
Markus Armbruster
AppliedQuoted 1 line · Peter Maydell
These patches fix some -Wshadow warnings in arm related code.
Queued, thanks!