[v2] examples: compilation fix for GCC-12

Message ID 20220902074337.3129786-1-amitprakashs@marvell.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series [v2] examples: compilation fix for GCC-12 |

Checks

Context Check Description
ci/checkpatch warning coding style issues
ci/Intel-compilation success Compilation OK
ci/github-robot: build success github build: passed
ci/intel-Testing success Testing PASS

Commit Message

Amit Prakash Shukla Sept. 2, 2022, 7:43 a.m. UTC
  GCC-12 warns when a pointer of type union points to an array of same
defined size, as union internally gets paded with pad bytes.

../examples/common/neon/port_group.h:42:21: error: array subscript
	'union <anonymous>[0]' is partly outside array bounds of
	'uint16_t[5]' {aka 'short unsigned int[5]'}
	[-Werror=array-bounds]
   42 |                 pnum->u64 = gptbl[v].pnum;
      |                     ^~
../examples/common/neon/port_group.h:21:23: note: object 'pn' of
	size [0, 10]
   21 | port_groupx4(uint16_t pn[FWDSTEP + 1], uint16_t *lp, uint16x8_t dp1
      |              ~~~~~~~~~^~~~~~~~~~~~~~~
../examples/common/neon/port_group.h:43:21: error: array subscript
	'union <anonymous>[0]' is partly outside array bounds of
	'uint16_t[5]' {aka 'short unsigned int[5]'} [-Werror=array-bounds]
   43 |                 pnum->u16[FWDSTEP] = 1;
      |                     ^~

Fixes: bdfc3816fbfc ("examples: common packet group functionality")
Cc: stable@dpdk.org

Signed-off-by: Amit Prakash Shukla <amitprakashs@marvell.com>
---
v2:
- Changed to __rte_packed instead of direct attribute

 examples/common/neon/port_group.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Amit Prakash Shukla Oct. 6, 2022, 6:31 a.m. UTC | #1
checkpatch complains about coding style error. It looks like a false positive ? 

Please suggest.

Thanks,
Amit Shukla

> -----Original Message-----
> From: Amit Prakash Shukla <amitprakashs@marvell.com>
> Sent: Friday, September 2, 2022 1:14 PM
> To: Ruifeng Wang <ruifeng.wang@arm.com>
> Cc: dev@dpdk.org; Jerin Jacob Kollanukkaran <jerinj@marvell.com>;
> stable@dpdk.org; Akhil Goyal <gakhil@marvell.com>;
> stephen@networkplumber.org; Amit Prakash Shukla
> <amitprakashs@marvell.com>
> Subject: [PATCH v2] examples: compilation fix for GCC-12
> 
> GCC-12 warns when a pointer of type union points to an array of same
> defined size, as union internally gets paded with pad bytes.
> 
> ../examples/common/neon/port_group.h:42:21: error: array subscript
> 	'union <anonymous>[0]' is partly outside array bounds of
> 	'uint16_t[5]' {aka 'short unsigned int[5]'}
> 	[-Werror=array-bounds]
>    42 |                 pnum->u64 = gptbl[v].pnum;
>       |                     ^~
> ../examples/common/neon/port_group.h:21:23: note: object 'pn' of
> 	size [0, 10]
>    21 | port_groupx4(uint16_t pn[FWDSTEP + 1], uint16_t *lp, uint16x8_t dp1
>       |              ~~~~~~~~~^~~~~~~~~~~~~~~
> ../examples/common/neon/port_group.h:43:21: error: array subscript
> 	'union <anonymous>[0]' is partly outside array bounds of
> 	'uint16_t[5]' {aka 'short unsigned int[5]'} [-Werror=array-bounds]
>    43 |                 pnum->u16[FWDSTEP] = 1;
>       |                     ^~
> 
> Fixes: bdfc3816fbfc ("examples: common packet group functionality")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Amit Prakash Shukla <amitprakashs@marvell.com>
> ---
> v2:
> - Changed to __rte_packed instead of direct attribute
> 
>  examples/common/neon/port_group.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/examples/common/neon/port_group.h
> b/examples/common/neon/port_group.h
> index 82c6ed6d73..04e5699f70 100644
> --- a/examples/common/neon/port_group.h
> +++ b/examples/common/neon/port_group.h
> @@ -24,7 +24,7 @@ port_groupx4(uint16_t pn[FWDSTEP + 1], uint16_t *lp,
> uint16x8_t dp1,
>  	union {
>  		uint16_t u16[FWDSTEP + 1];
>  		uint64_t u64;
> -	} *pnum = (void *)pn;
> +	} __rte_packed *pnum = (void *)pn;
> 
>  	uint16x8_t mask = {1, 2, 4, 8, 0, 0, 0, 0};
>  	int32_t v;
> --
> 2.25.1
  
Thomas Monjalon Oct. 6, 2022, 9:21 a.m. UTC | #2
06/10/2022 08:31, Amit Prakash Shukla:
> checkpatch complains about coding style error. It looks like a false positive ?

Yes we can ignore this checkpatch warning.
  
Thomas Monjalon Oct. 6, 2022, 9:27 a.m. UTC | #3
02/09/2022 09:43, Amit Prakash Shukla:
> GCC-12 warns when a pointer of type union points to an array of same
> defined size, as union internally gets paded with pad bytes.
> 
> ../examples/common/neon/port_group.h:42:21: error: array subscript
> 	'union <anonymous>[0]' is partly outside array bounds of
> 	'uint16_t[5]' {aka 'short unsigned int[5]'}
> 	[-Werror=array-bounds]
>    42 |                 pnum->u64 = gptbl[v].pnum;
>       |                     ^~
> ../examples/common/neon/port_group.h:21:23: note: object 'pn' of
> 	size [0, 10]
>    21 | port_groupx4(uint16_t pn[FWDSTEP + 1], uint16_t *lp, uint16x8_t dp1
>       |              ~~~~~~~~~^~~~~~~~~~~~~~~
> ../examples/common/neon/port_group.h:43:21: error: array subscript
> 	'union <anonymous>[0]' is partly outside array bounds of
> 	'uint16_t[5]' {aka 'short unsigned int[5]'} [-Werror=array-bounds]
>    43 |                 pnum->u16[FWDSTEP] = 1;
>       |                     ^~
> 
> Fixes: bdfc3816fbfc ("examples: common packet group functionality")

Should be:
Fixes: 732115ce38c6 ("examples/l3fwd: move packet group function in common")

> Cc: stable@dpdk.org
> 
> Signed-off-by: Amit Prakash Shukla <amitprakashs@marvell.com>

Applied, thanks.
  

Patch

diff --git a/examples/common/neon/port_group.h b/examples/common/neon/port_group.h
index 82c6ed6d73..04e5699f70 100644
--- a/examples/common/neon/port_group.h
+++ b/examples/common/neon/port_group.h
@@ -24,7 +24,7 @@  port_groupx4(uint16_t pn[FWDSTEP + 1], uint16_t *lp, uint16x8_t dp1,
 	union {
 		uint16_t u16[FWDSTEP + 1];
 		uint64_t u64;
-	} *pnum = (void *)pn;
+	} __rte_packed *pnum = (void *)pn;
 
 	uint16x8_t mask = {1, 2, 4, 8, 0, 0, 0, 0};
 	int32_t v;