[v3] lib/fib: remove warning about implicit 64-bit conversion

Message ID 1741042492-6700-1-git-send-email-andremue@linux.microsoft.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series [v3] lib/fib: remove warning about implicit 64-bit conversion |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/github-robot: build success github build: passed
ci/iol-mellanox-Performance success Performance Testing PASS
ci/intel-Functional success Functional PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-unit-amd64-testing success Testing PASS
ci/iol-sample-apps-testing success Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-compile-amd64-testing success Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-compile-arm64-testing success Testing PASS
ci/iol-marvell-Functional success Functional Testing PASS

Commit Message

Andre Muezerie March 3, 2025, 10:54 p.m. UTC
MSVC issues the warning below:

../lib/fib/trie.c(341): warning C4334: '<<':
result of 32-bit shift implicitly converted to 64 bits
(was 64-bit shift intended?)

The fix is to cast the result explicitly to uintptr_t since it is used
in pointer arithmetic.

Signed-off-by: Andre Muezerie <andremue@linux.microsoft.com>
---
 lib/fib/trie.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Stephen Hemminger March 4, 2025, 6:49 a.m. UTC | #1
Better to cast the constant (1) to avoid warning,
.
That is what other code does like RTE_BIT macros

On Mon, Mar 3, 2025, 23:55 Andre Muezerie <andremue@linux.microsoft.com>
wrote:

> MSVC issues the warning below:
>
> ../lib/fib/trie.c(341): warning C4334: '<<':
> result of 32-bit shift implicitly converted to 64 bits
> (was 64-bit shift intended?)
>
> The fix is to cast the result explicitly to uintptr_t since it is used
> in pointer arithmetic.
>
> Signed-off-by: Andre Muezerie <andremue@linux.microsoft.com>
> ---
>  lib/fib/trie.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/lib/fib/trie.c b/lib/fib/trie.c
> index 4893f6c636..bf9f63eaa2 100644
> --- a/lib/fib/trie.c
> +++ b/lib/fib/trie.c
> @@ -338,7 +338,7 @@ write_edge(struct rte_trie_tbl *dp, const uint8_t
> *ip_part, uint64_t next_hop,
>                 if (ret < 0)
>                         return ret;
>                 if (edge == LEDGE) {
> -                       write_to_dp((uint8_t *)p + (1 << dp->nh_sz),
> +                       write_to_dp((uint8_t *)p + (uintptr_t)(1 <<
> dp->nh_sz),
>                                 next_hop << 1, dp->nh_sz, UINT8_MAX -
> *ip_part);
>                 } else {
>                         write_to_dp(get_tbl_p_by_idx(dp->tbl8, tbl8_idx *
> --
> 2.48.1.vfs.0.0
>
>
  
Bruce Richardson March 4, 2025, 10:47 a.m. UTC | #2
On Mon, Mar 03, 2025 at 02:54:52PM -0800, Andre Muezerie wrote:
> MSVC issues the warning below:
> 
> ../lib/fib/trie.c(341): warning C4334: '<<':
> result of 32-bit shift implicitly converted to 64 bits
> (was 64-bit shift intended?)
> 
> The fix is to cast the result explicitly to uintptr_t since it is used
> in pointer arithmetic.
> 
> Signed-off-by: Andre Muezerie <andremue@linux.microsoft.com>
> ---
>  lib/fib/trie.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/lib/fib/trie.c b/lib/fib/trie.c
> index 4893f6c636..bf9f63eaa2 100644
> --- a/lib/fib/trie.c
> +++ b/lib/fib/trie.c
> @@ -338,7 +338,7 @@ write_edge(struct rte_trie_tbl *dp, const uint8_t *ip_part, uint64_t next_hop,
>  		if (ret < 0)
>  			return ret;
>  		if (edge == LEDGE) {
> -			write_to_dp((uint8_t *)p + (1 << dp->nh_sz),
> +			write_to_dp((uint8_t *)p + (uintptr_t)(1 << dp->nh_sz),

Might be worth considering using the RTE_PTR_ADD macro too for this line.

/Bruce
  
Andre Muezerie March 4, 2025, 4:51 p.m. UTC | #3
On Mon, Mar 03, 2025 at 10:49:52PM -0800, Stephen Hemminger wrote:
> Better to cast the constant (1) to avoid warning,
> .
> That is what other code does like RTE_BIT macros

Alright, I made that change in v4.

> 
> On Mon, Mar 3, 2025, 23:55 Andre Muezerie <andremue@linux.microsoft.com>
> wrote:
> 
> > MSVC issues the warning below:
> >
> > ../lib/fib/trie.c(341): warning C4334: '<<':
> > result of 32-bit shift implicitly converted to 64 bits
> > (was 64-bit shift intended?)
> >
> > The fix is to cast the result explicitly to uintptr_t since it is used
> > in pointer arithmetic.
> >
> > Signed-off-by: Andre Muezerie <andremue@linux.microsoft.com>
> > ---
> >  lib/fib/trie.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/lib/fib/trie.c b/lib/fib/trie.c
> > index 4893f6c636..bf9f63eaa2 100644
> > --- a/lib/fib/trie.c
> > +++ b/lib/fib/trie.c
> > @@ -338,7 +338,7 @@ write_edge(struct rte_trie_tbl *dp, const uint8_t
> > *ip_part, uint64_t next_hop,
> >                 if (ret < 0)
> >                         return ret;
> >                 if (edge == LEDGE) {
> > -                       write_to_dp((uint8_t *)p + (1 << dp->nh_sz),
> > +                       write_to_dp((uint8_t *)p + (uintptr_t)(1 <<
> > dp->nh_sz),
> >                                 next_hop << 1, dp->nh_sz, UINT8_MAX -
> > *ip_part);
> >                 } else {
> >                         write_to_dp(get_tbl_p_by_idx(dp->tbl8, tbl8_idx *
> > --
> > 2.48.1.vfs.0.0
> >
> >
  
Andre Muezerie March 4, 2025, 4:52 p.m. UTC | #4
On Tue, Mar 04, 2025 at 10:47:28AM +0000, Bruce Richardson wrote:
> On Mon, Mar 03, 2025 at 02:54:52PM -0800, Andre Muezerie wrote:
> > MSVC issues the warning below:
> > 
> > ../lib/fib/trie.c(341): warning C4334: '<<':
> > result of 32-bit shift implicitly converted to 64 bits
> > (was 64-bit shift intended?)
> > 
> > The fix is to cast the result explicitly to uintptr_t since it is used
> > in pointer arithmetic.
> > 
> > Signed-off-by: Andre Muezerie <andremue@linux.microsoft.com>
> > ---
> >  lib/fib/trie.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/lib/fib/trie.c b/lib/fib/trie.c
> > index 4893f6c636..bf9f63eaa2 100644
> > --- a/lib/fib/trie.c
> > +++ b/lib/fib/trie.c
> > @@ -338,7 +338,7 @@ write_edge(struct rte_trie_tbl *dp, const uint8_t *ip_part, uint64_t next_hop,
> >  		if (ret < 0)
> >  			return ret;
> >  		if (edge == LEDGE) {
> > -			write_to_dp((uint8_t *)p + (1 << dp->nh_sz),
> > +			write_to_dp((uint8_t *)p + (uintptr_t)(1 << dp->nh_sz),
> 
> Might be worth considering using the RTE_PTR_ADD macro too for this line.

Makes sense. I'm using RTE_PTR_ADD in v4.
Thanks for the suggestion.

> 
> /Bruce
  

Patch

diff --git a/lib/fib/trie.c b/lib/fib/trie.c
index 4893f6c636..bf9f63eaa2 100644
--- a/lib/fib/trie.c
+++ b/lib/fib/trie.c
@@ -338,7 +338,7 @@  write_edge(struct rte_trie_tbl *dp, const uint8_t *ip_part, uint64_t next_hop,
 		if (ret < 0)
 			return ret;
 		if (edge == LEDGE) {
-			write_to_dp((uint8_t *)p + (1 << dp->nh_sz),
+			write_to_dp((uint8_t *)p + (uintptr_t)(1 << dp->nh_sz),
 				next_hop << 1, dp->nh_sz, UINT8_MAX - *ip_part);
 		} else {
 			write_to_dp(get_tbl_p_by_idx(dp->tbl8, tbl8_idx *