Skip to contentSkip to conversation

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

PATCH Superseded Andre Muezerie 5 participants 17 messages Dec 4, 2024 – Jun 3, 2025 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib/fib: remove warning about implicit 64-bit conversion

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 ptrdiff_t since it is used in pointer arithmetic.

---
 lib/fib/trie.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/fib/trie.c +1 -1
index 4893f6c636..997b7cc338 100644
@@ -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 + (ptrdiff_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 *
Signature · 1 line
2.47.0.vfs.0.3
#1 lore raw
Quoted 19 lines · On Tue, 3 Dec 2024 18:56:50 -0800 Andre Muezerie…

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 ptrdiff_t since it is used in pointer arithmetic.

---
 lib/fib/trie.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/fib/trie.c +0 -0
index 4893f6c636..997b7cc338 100644

lib/fib/trie.c write_edge(struct rte_trie_tbl *dp, const uint8_t *ip_part, uint64_t next_hop, · line 342

Quoted 6 lines
lib/fib/trie.c +1 -1
@@ -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 + (ptrdiff_t)(1 << dp->nh_sz),
 				next_hop << 1, dp->nh_sz, UINT8_MAX - *ip_part);

You would be better to use a 64 bit shift or RTE_BIT64 for this.

			write_to_dp((uint8_t *)p + ((uintptr_t)1 << dp->nh_sz),
#2 lore raw
Quoted 31 lines · Stephen Hemminger
Quoted 19 lines · On Tue, 3 Dec 2024 18:56:50 -0800 Andre Muezerie…

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 ptrdiff_t since it is used in pointer arithmetic.

---
 lib/fib/trie.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/fib/trie.c +0 -0
index 4893f6c636..997b7cc338 100644

lib/fib/trie.c write_edge(struct rte_trie_tbl *dp, const uint8_t *ip_part, uint64_t next_hop, · line 342

Quoted 6 lines
lib/fib/trie.c +1 -1
@@ -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 + (ptrdiff_t)(1 << dp->nh_sz),
 				next_hop << 1, dp->nh_sz, UINT8_MAX - *ip_part);

You would be better to use a 64 bit shift or RTE_BIT64 for this.

Quoted 1 line
			write_to_dp((uint8_t *)p + ((uintptr_t)1 << dp->nh_sz),

Thanks for the suggestion. I'll update the patch.

#3 lore raw

PATCH v2 1/1 lib/fib: remove warning about implicit 64-bit conversion

In reply to Andre Muezerie

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 ptrdiff_t since it is used in pointer arithmetic.

---
 lib/fib/trie.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/fib/trie.c +1 -1
index 4893f6c636..959cb8803c 100644
@@ -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 *
Signature · 1 line
2.47.0.vfs.0.3
#4 lore raw

PATCH v3 1/1 lib/fib: remove warning about implicit 64-bit conversion

In reply to Andre Muezerie

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.

---
 lib/fib/trie.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/fib/trie.c +1 -1
index 4893f6c636..bf9f63eaa2 100644
@@ -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 *
Signature · 1 line
2.48.1.vfs.0.0
#5 lore raw

Better to cast the constant (1) to avoid warning,
.
That is what other code does like RTE_BIT macros

Quoted 34 lines · On Mon, Mar 3, 2025, 23:55 Andre Muezerie <[email protected]> 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.

---
 lib/fib/trie.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/fib/trie.c +1 -1
index 4893f6c636..bf9f63eaa2 100644
@@ -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

#6 lore raw
Quoted 3 lines · Stephen Hemminger

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.

Quoted 38 lines
Quoted 34 lines · On Mon, Mar 3, 2025, 23:55 Andre Muezerie <[email protected]> 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.

---
 lib/fib/trie.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/fib/trie.c +1 -1
index 4893f6c636..bf9f63eaa2 100644
@@ -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

#7 lore raw
In reply to Andre Muezerie
Quoted 19 lines · Andre Muezerie

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.

---
 lib/fib/trie.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/fib/trie.c +0 -0
index 4893f6c636..bf9f63eaa2 100644

lib/fib/trie.c write_edge(struct rte_trie_tbl *dp, const uint8_t *ip_part, uint64_t next_hop, · line 341

Quoted 5 lines
lib/fib/trie.c +1 -1
@@ -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

#8 lore raw
Quoted 15 lines · Bruce Richardson
Quoted 14 lines · Andre Muezerie

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.

---
 lib/fib/trie.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 12 lines

lib/fib/trie.c write_edge(struct rte_trie_tbl *dp, const uint8_t *ip_part, uint64_t next_hop, · line 341

Quoted 10 lines
lib/fib/trie.c +1 -1
index 4893f6c636..bf9f63eaa2 100644
@@ -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.

Quoted 2 lines

/Bruce

#9 lore raw

PATCH v4 1/1 lib/fib: remove warning about implicit 64-bit conversion

In reply to Andre Muezerie

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.

---
 lib/fib/trie.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/fib/trie.c +1 -1
index 4893f6c636..f077b65a28 100644
@@ -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 *
Signature · 1 line
2.48.1.vfs.0.0
#10 lore raw

v5 cover enable fib to be compiled with MSVC

In reply to Andre Muezerie

This patchset addresses the issues in lib/fib that were preventing compilation with MSVC. The first patch removes a warning about implicit 64-bit conversion, and the second patch enables the compilation of fib with MSVC.

v5:
- enabled fib to be compiled with MSVC

Andre Muezerie (2):
lib/fib: remove warning about implicit 64-bit conversion lib/fib: enable fib to be compiled with MSVC

 lib/fib/meson.build | 6 ------
 lib/fib/trie.c      | 2 +-
 2 files changed, 1 insertion(+), 7 deletions(-)

--
2.49.0.vfs.0.3

#11 lore raw

PATCH v5 1/2 lib/fib: remove warning about implicit 64-bit conversion

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.

---
 lib/fib/trie.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/fib/trie.c +1 -1
index 6c20057ac5..24a08b827d 100644
@@ -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 *
Signature · 1 line
2.49.0.vfs.0.3
Reviewed-by on v5 1/2
#12 lore raw
Quoted 34 lines

From: Andre Muezerie [mailto:[email protected]]
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.

---
 lib/fib/trie.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/fib/trie.c +1 -1
index 6c20057ac5..24a08b827d 100644
@@ -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);

lib/fib/trie.c +0 -1
 		} else {
 			write_to_dp(get_tbl_p_by_idx(dp->tbl8, tbl8_idx *
--
Quoted 1 line

2.49.0.vfs.0.3

#13 lore raw
In reply to Andre Muezerie

Ok.
Wonder if RTE_PTR_ADD should have the cast there instead

Quoted 34 lines · On Sat, May 17, 2025, 05:45 Andre Muezerie <[email protected]> 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.

---
 lib/fib/trie.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/fib/trie.c +1 -1
index 6c20057ac5..24a08b827d 100644
@@ -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

#14 lore raw

From: Stephen Hemminger [mailto:[email protected]]
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 <[email protected]> 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.

---
 lib/fib/trie.c | 2 +-

 1 file changed, 1 insertion(+), 1 deletion(-)
lib/fib/trie.c +0 -0
index 6c20057ac5..24a08b827d 100644
@@ -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 *

Signature · 1 line
2.49.0.vfs.0.3
#15 lore raw

PATCH v5 2/2 lib/fib: enable fib to be compiled with MSVC

In reply to Andre Muezerie

Now that all issues related to fib are addressed it can be enabled for MSVC.

---
 lib/fib/meson.build | 6 ------
 1 file changed, 6 deletions(-)
lib/fib/meson.build +0 -6
index da82e017a9..6992ccc040 100644
@@ -2,12 +2,6 @@
 # Copyright(c) 2018 Vladimir Medvedkin <[email protected]>
 # Copyright(c) 2019 Intel Corporation
 
-if is_ms_compiler
-    build = false
-    reason = 'not supported building with Visual Studio Toolset'
-    subdir_done()
-endif
-
 sources = files('rte_fib.c', 'rte_fib6.c', 'dir24_8.c', 'trie.c')
 headers = files('rte_fib.h', 'rte_fib6.h')
 deps += ['rib']
Signature · 1 line
2.49.0.vfs.0.3
#16 lore raw

Re: [PATCH v5 0/2] enable fib to be compiled with MSVC

In reply to Andre Muezerie
Quoted 5 lines · Andre Muezerie

This patchset addresses the issues in lib/fib that were preventing compilation with MSVC. The first patch removes a warning about implicit 64-bit conversion, and the second patch enables the compilation of fib with MSVC.

Series applied, thanks.

Signature · 1 line
David Marchand