[v5,1/2] lib/fib: remove warning about implicit 64-bit conversion

Message ID 1747428335-3736-2-git-send-email-andremue@linux.microsoft.com (mailing list archive)
State Accepted
Delegated to: David Marchand
Headers
Series enable fib to be compiled with MSVC |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Andre Muezerie May 16, 2025, 8:45 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 (1) 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

Morten Brørup May 17, 2025, 10:07 a.m. UTC | #1
> From: Andre Muezerie [mailto:andremue@linux.microsoft.com]
> Sent: Friday, 16 May 2025 22.46
> 
> 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 (1) 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 6c20057ac5..24a08b827d 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(RTE_PTR_ADD(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.49.0.vfs.0.3

Reviewed-by: Morten Brørup <mb@smartsharesystems.com>
  
Stephen Hemminger May 17, 2025, 11:09 a.m. UTC | #2
Ok.
Wonder if RTE_PTR_ADD should have the cast there instead

On Sat, May 17, 2025, 05:45 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 (1) 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 6c20057ac5..24a08b827d 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(RTE_PTR_ADD(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.49.0.vfs.0.3
>
>
  
Morten Brørup May 17, 2025, 12:59 p.m. UTC | #3
From: Stephen Hemminger [mailto:stephen@networkplumber.org] 
Sent: Saturday, 17 May 2025 13.10

Ok.
Wonder if RTE_PTR_ADD should have the cast there instead 

Morten: Considered the same; but prefer not. It will suppress warnings like this, which may be real.


On Sat, May 17, 2025, 05:45 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 (1) 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 6c20057ac5..24a08b827d 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(RTE_PTR_ADD(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.49.0.vfs.0.3
  

Patch

diff --git a/lib/fib/trie.c b/lib/fib/trie.c
index 6c20057ac5..24a08b827d 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(RTE_PTR_ADD(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 *