Skip to contentSkip to conversation

verbs: fix compilation warning with C++20

PATCH Superseded Daniel Vacek 5 participants 13 messages Jun 9, 2023 – Jul 5, 2023 InfiniBand

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 verbs: fix compilation warning with C++20

Our customer reported the below warning whe using Clang v16.0.4 and C++20, on a code that includes the header "/usr/include/infiniband/verbs.h":

error: bitwise operation between different enumeration types ('ibv_access_flags' and 'ib_uverbs_access_flags') is deprecated [-Werror,-Wdeprecated-enum-enum-conversion]

                mem->mr = ibv_reg_mr(dev->pd, (void*)start, len, IBV_ACCESS_LOCAL_WRITE);
                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/infiniband/verbs.h:2514:19: note: expanded from macro 'ibv_reg_mr'
                             ((access) & IBV_ACCESS_OPTIONAL_RANGE) == 0))
                              ~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~

1 error generated.

According to the article "Clang 11 warning: Bitwise operation between different enumeration types is deprecated":

C++20's P1120R0 deprecated bitwise operations between different enums. Such code is likely to become ill-formed in C++23. Clang 11 warns about such cases. It should be fixed.

---
 libibverbs/verbs.h     | 4 +++-
 libibverbs/verbs_api.h | 1 -
 2 files changed, 3 insertions(+), 2 deletions(-)
libibverbs/verbs.h +3 -1
index 03a7a2a7..85995abe 100644
@@ -617,7 +617,9 @@ enum ibv_access_flags {
 	IBV_ACCESS_HUGETLB		= (1<<7),
 	IBV_ACCESS_FLUSH_GLOBAL		= (1 << 8),
 	IBV_ACCESS_FLUSH_PERSISTENT	= (1 << 9),
-	IBV_ACCESS_RELAXED_ORDERING	= IBV_ACCESS_OPTIONAL_FIRST,
+
+	IBV_ACCESS_RELAXED_ORDERING	= IBV_ACCESS_OPTIONAL_FIRST,		// bit 20
+	IBV_ACCESS_OPTIONAL_RANGE	= IB_UVERBS_ACCESS_OPTIONAL_RANGE	// mask of bits 20-29
 };
 
 struct ibv_mw_bind_info {
libibverbs/verbs_api.h +0 -1
index 309f6fba..7a5f0cdf 100644
@@ -94,7 +94,6 @@
 
 #define IBV_QPF_GRH_REQUIRED				IB_UVERBS_QPF_GRH_REQUIRED
 
-#define IBV_ACCESS_OPTIONAL_RANGE			IB_UVERBS_ACCESS_OPTIONAL_RANGE
 #define IBV_ACCESS_OPTIONAL_FIRST			IB_UVERBS_ACCESS_OPTIONAL_FIRST
 #endif
 
Signature · 1 line
2.40.1
#1 lore raw
Quoted 10 lines · Daniel Vacek

Our customer reported the below warning whe using Clang v16.0.4 and C++20, on a code that includes the header "/usr/include/infiniband/verbs.h":

error: bitwise operation between different enumeration types ('ibv_access_flags' and 'ib_uverbs_access_flags') is deprecated [-Werror,-Wdeprecated-enum-enum-conversion]

                mem->mr = ibv_reg_mr(dev->pd, (void*)start, len, IBV_ACCESS_LOCAL_WRITE);
                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/infiniband/verbs.h:2514:19: note: expanded from macro 'ibv_reg_mr'
                             ((access) & IBV_ACCESS_OPTIONAL_RANGE) == 0))
                              ~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~
Quoted 7 lines

1 error generated.

According to the article "Clang 11 warning: Bitwise operation between different enumeration types is deprecated":

C++20's P1120R0 deprecated bitwise operations between different enums. Such code is likely to become ill-formed in C++23. Clang 11 warns about such cases. It should be fixed.

There should be a cast to an integer in the macro, we can't know what the user will pass in there and it may not be that enum.

Jason

#2 lore raw
Quoted 14 lines · Jason Gunthorpe
Quoted 12 lines · Daniel Vacek

Our customer reported the below warning whe using Clang v16.0.4 and C++20, on a code that includes the header "/usr/include/infiniband/verbs.h":

error: bitwise operation between different enumeration types ('ibv_access_flags' and 'ib_uverbs_access_flags') is deprecated [-Werror,-Wdeprecated-enum-enum-conversion]

                mem->mr = ibv_reg_mr(dev->pd, (void*)start, len, IBV_ACCESS_LOCAL_WRITE);
                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/infiniband/verbs.h:2514:19: note: expanded from macro 'ibv_reg_mr'
                             ((access) & IBV_ACCESS_OPTIONAL_RANGE) == 0))
                              ~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~

1 error generated.

Quoted 8 lines
Quoted 5 lines

According to the article "Clang 11 warning: Bitwise operation between different enumeration types is deprecated":

C++20's P1120R0 deprecated bitwise operations between different enums. Such code is likely to become ill-formed in C++23. Clang 11 warns about such cases. It should be fixed.

There should be a cast to an integer in the macro, we can't know what the user will pass in there and it may not be that enum.

Hmm, if the user passes a definition from the header files at least we should be consistent I'd say, which is this case. No one was passing any custom values here.
If you cast to an integer here you may start silently hiding possible errors. If the user passes any custom value, IMO, it's his responsibility to make it right.

I forgot to explicitly mention before that this change was tested and it addresses the warning successfully.

--nX

Quoted 2 lines

Jason

#3 lore raw
Quoted 24 lines · Daniel Vacek
Quoted 14 lines · Jason Gunthorpe
Quoted 12 lines · Daniel Vacek

Our customer reported the below warning whe using Clang v16.0.4 and C++20, on a code that includes the header "/usr/include/infiniband/verbs.h":

error: bitwise operation between different enumeration types ('ibv_access_flags' and 'ib_uverbs_access_flags') is deprecated [-Werror,-Wdeprecated-enum-enum-conversion]

                mem->mr = ibv_reg_mr(dev->pd, (void*)start, len, IBV_ACCESS_LOCAL_WRITE);
                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/infiniband/verbs.h:2514:19: note: expanded from macro 'ibv_reg_mr'
                             ((access) & IBV_ACCESS_OPTIONAL_RANGE) == 0))
                              ~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~

1 error generated.

Quoted 8 lines
Quoted 5 lines

According to the article "Clang 11 warning: Bitwise operation between different enumeration types is deprecated":

C++20's P1120R0 deprecated bitwise operations between different enums. Such code is likely to become ill-formed in C++23. Clang 11 warns about such cases. It should be fixed.

There should be a cast to an integer in the macro, we can't know what the user will pass in there and it may not be that enum.

Quoted 6 lines

Hmm, if the user passes a definition from the header files at least we should be consistent I'd say, which is this case. No one was passing any custom values here.
If you cast to an integer here you may start silently hiding possible errors. If the user passes any custom value, IMO, it's his responsibility to make it right.

The signature of the API is to accept an int, we cannot demand any more of that from the user. The macro wiped out the type cast to an int, it should put it back.

Jason

#4 lore raw
Quoted 31 lines · Jason Gunthorpe
Quoted 23 lines · Daniel Vacek
Quoted 13 lines · Jason Gunthorpe
Quoted 12 lines · Daniel Vacek

Our customer reported the below warning whe using Clang v16.0.4 and C++20, on a code that includes the header "/usr/include/infiniband/verbs.h":

error: bitwise operation between different enumeration types ('ibv_access_flags' and 'ib_uverbs_access_flags') is deprecated [-Werror,-Wdeprecated-enum-enum-conversion]

                mem->mr = ibv_reg_mr(dev->pd, (void*)start, len, IBV_ACCESS_LOCAL_WRITE);
                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/infiniband/verbs.h:2514:19: note: expanded from macro 'ibv_reg_mr'
                             ((access) & IBV_ACCESS_OPTIONAL_RANGE) == 0))
                              ~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~

1 error generated.

Quoted 8 lines
Quoted 5 lines

According to the article "Clang 11 warning: Bitwise operation between different enumeration types is deprecated":

C++20's P1120R0 deprecated bitwise operations between different enums. Such code is likely to become ill-formed in C++23. Clang 11 warns about such cases. It should be fixed.

There should be a cast to an integer in the macro, we can't know what the user will pass in there and it may not be that enum.

Quoted 6 lines

Hmm, if the user passes a definition from the header files at least we should be consistent I'd say, which is this case. No one was passing any custom values here.
If you cast to an integer here you may start silently hiding possible errors. If the user passes any custom value, IMO, it's his responsibility to make it right.

Quoted 3 lines

The signature of the API is to accept an int, we cannot demand any more of that from the user. The macro wiped out the type cast to an int, it should put it back.

Oh, I see. In that case shall we still keep this patch or just do the cast?

--nX

Quoted 2 lines

Jason

#5 lore raw
Quoted 32 lines · Daniel Vacek
Quoted 31 lines · Jason Gunthorpe
Quoted 29 lines · Daniel Vacek
Quoted 13 lines · Jason Gunthorpe
Quoted 12 lines · Daniel Vacek

Our customer reported the below warning whe using Clang v16.0.4 and C++20, on a code that includes the header "/usr/include/infiniband/verbs.h":

error: bitwise operation between different enumeration types ('ibv_access_flags' and 'ib_uverbs_access_flags') is deprecated [-Werror,-Wdeprecated-enum-enum-conversion]

                mem->mr = ibv_reg_mr(dev->pd, (void*)start, len, IBV_ACCESS_LOCAL_WRITE);
                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/infiniband/verbs.h:2514:19: note: expanded from macro 'ibv_reg_mr'
                             ((access) & IBV_ACCESS_OPTIONAL_RANGE) == 0))
                              ~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~

1 error generated.

Quoted 8 lines
Quoted 5 lines

According to the article "Clang 11 warning: Bitwise operation between different enumeration types is deprecated":

C++20's P1120R0 deprecated bitwise operations between different enums. Such code is likely to become ill-formed in C++23. Clang 11 warns about such cases. It should be fixed.

There should be a cast to an integer in the macro, we can't know what the user will pass in there and it may not be that enum.

Hmm, if the user passes a definition from the header files at least we should be consistent I'd say, which is this case. No one was passing any custom values here.
If you cast to an integer here you may start silently hiding possible errors. If the user passes any custom value, IMO, it's his responsibility to make it right.

Quoted 6 lines
Quoted 3 lines

The signature of the API is to accept an int, we cannot demand any more of that from the user. The macro wiped out the type cast to an int, it should put it back.

Oh, I see. In that case shall we still keep this patch or just do the cast?

Just do the cast

Jason

#6 lore raw

PATCH v2 1/1 verbs: fix compilation warning with C++20

In reply to Daniel Vacek

Our customer reported the below warning whe using Clang v16.0.4 and C++20, on a code that includes the header "/usr/include/infiniband/verbs.h":

error: bitwise operation between different enumeration types ('ibv_access_flags' and 'ib_uverbs_access_flags') is deprecated [-Werror,-Wdeprecated-enum-enum-conversion]

                mem->mr = ibv_reg_mr(dev->pd, (void*)start, len, IBV_ACCESS_LOCAL_WRITE);
                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/infiniband/verbs.h:2514:19: note: expanded from macro 'ibv_reg_mr'
                             ((access) & IBV_ACCESS_OPTIONAL_RANGE) == 0))
                              ~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~

1 error generated.

According to the article "Clang 11 warning: Bitwise operation between different enumeration types is deprecated":

C++20's P1120R0 deprecated bitwise operations between different enums. Such code is likely to become ill-formed in C++23. Clang 11 warns about such cases. It should be fixed.

---
 libibverbs/verbs.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
libibverbs/verbs.h +1 -1
index 03a7a2a7..ed9aed21 100644
@@ -2590,7 +2590,7 @@ __ibv_reg_mr(struct ibv_pd *pd, void *addr, size_t length, unsigned int access,
 #define ibv_reg_mr(pd, addr, length, access)                                   \
 	__ibv_reg_mr(pd, addr, length, access,                                 \
 		     __builtin_constant_p(				       \
-			     ((access) & IBV_ACCESS_OPTIONAL_RANGE) == 0))
+			     ((int)(access) & IBV_ACCESS_OPTIONAL_RANGE) == 0))
 
 /**
  * ibv_reg_mr_iova - Register a memory region with a virtual offset
Signature · 1 line
2.40.1
#7 lore raw

Adding CC: Jason

--nX

Quoted 41 lines · Daniel Vacek

Our customer reported the below warning whe using Clang v16.0.4 and C++20, on a code that includes the header "/usr/include/infiniband/verbs.h":

error: bitwise operation between different enumeration types ('ibv_access_flags' and 'ib_uverbs_access_flags') is deprecated [-Werror,-Wdeprecated-enum-enum-conversion]

                mem->mr = ibv_reg_mr(dev->pd, (void*)start, len, IBV_ACCESS_LOCAL_WRITE);
                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/infiniband/verbs.h:2514:19: note: expanded from macro 'ibv_reg_mr'
                             ((access) & IBV_ACCESS_OPTIONAL_RANGE) == 0))
                              ~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~

1 error generated.

According to the article "Clang 11 warning: Bitwise operation between different enumeration types is deprecated":

C++20's P1120R0 deprecated bitwise operations between different enums. Such code is likely to become ill-formed in C++23. Clang 11 warns about such cases. It should be fixed.

---
 libibverbs/verbs.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
libibverbs/verbs.h +1 -2
index 03a7a2a7..ed9aed21 100644
@@ -2590,7 +2590,7 @@ __ibv_reg_mr(struct ibv_pd *pd, void *addr, size_t length, unsigned int access,
 #define ibv_reg_mr(pd, addr, length, access)                                   \
        __ibv_reg_mr(pd, addr, length, access,                                 \
                     __builtin_constant_p(                                     \
-                            ((access) & IBV_ACCESS_OPTIONAL_RANGE) == 0))
+                            ((int)(access) & IBV_ACCESS_OPTIONAL_RANGE) == 0))
 
 /**
  * ibv_reg_mr_iova - Register a memory region with a virtual offset
--

2.40.1

#8 lore raw

Hi Eugene,

Red Hat provided another fix, could you try to reproduce the issue on my machine (sjcvl1-rogerio) and give me feedback?

Regards,
Rogerio

-----Original Message-----
From: Daniel Vacek <[email protected]>
Sent: Tuesday, June 20, 2023 6:20 AM
To: [email protected]; Jason Gunthorpe <[email protected]>
Cc: Leon Romanovsky <[email protected]>; Rogerio de Souza Moraes <[email protected]>
Subject: Re: [PATCH v2] verbs: fix compilation warning with C++20

EXTERNAL MAIL

Adding CC: Jason

--nX

Quoted 45 lines · Daniel Vacek

Our customer reported the below warning whe using Clang v16.0.4 and C++20, on a code that includes the header "/usr/include/infiniband/verbs.h":

error: bitwise operation between different enumeration types ('ibv_access_flags' and
'ib_uverbs_access_flags') is deprecated [-Werror,-Wdeprecated-enum-enum-conversion]

                mem->mr = ibv_reg_mr(dev->pd, (void*)start, len, IBV_ACCESS_LOCAL_WRITE);

^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/infiniband/verbs.h:2514:19: note: expanded from macro 'ibv_reg_mr'

                             ((access) & IBV_ACCESS_OPTIONAL_RANGE) == 0))
                              ~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~

1 error generated.

According to the article "Clang 11 warning: Bitwise operation between different enumeration types is deprecated":

C++20's P1120R0 deprecated bitwise operations between different enums. C++Such code is
likely to become ill-formed in C++23. Clang 11 warns about such cases. It should be fixed.

---
 libibverbs/verbs.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
libibverbs/verbs.h index renamed from libibverbs/verbs.h +0 -0

03a7a2a7..ed9aed21 100644

libibverbs/verbs.h +2 -2
@@ -2590,7 +2590,7 @@ __ibv_reg_mr(struct ibv_pd *pd, void *addr, size_t length, unsigned int access,
 #define ibv_reg_mr(pd, addr, length, access)                                   \
        __ibv_reg_mr(pd, addr, length, access,                                 \
                     __builtin_constant_p(                                     \
-                            ((access) & IBV_ACCESS_OPTIONAL_RANGE) == 0))
+                            ((int)(access) & 
+ IBV_ACCESS_OPTIONAL_RANGE) == 0))
 
 /**
  * ibv_reg_mr_iova - Register a memory region with a virtual offset
--

2.40.1

#9 lore raw
In reply to Daniel Vacek

Bump.

Was this forgotten or overlooked?

--nX

Quoted 41 lines · Daniel Vacek

Our customer reported the below warning whe using Clang v16.0.4 and C++20, on a code that includes the header "/usr/include/infiniband/verbs.h":

error: bitwise operation between different enumeration types ('ibv_access_flags' and 'ib_uverbs_access_flags') is deprecated [-Werror,-Wdeprecated-enum-enum-conversion]

                mem->mr = ibv_reg_mr(dev->pd, (void*)start, len, IBV_ACCESS_LOCAL_WRITE);
                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/infiniband/verbs.h:2514:19: note: expanded from macro 'ibv_reg_mr'
                             ((access) & IBV_ACCESS_OPTIONAL_RANGE) == 0))
                              ~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~

1 error generated.

According to the article "Clang 11 warning: Bitwise operation between different enumeration types is deprecated":

C++20's P1120R0 deprecated bitwise operations between different enums. Such code is likely to become ill-formed in C++23. Clang 11 warns about such cases. It should be fixed.

---
 libibverbs/verbs.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
libibverbs/verbs.h +1 -2
index 03a7a2a7..ed9aed21 100644
@@ -2590,7 +2590,7 @@ __ibv_reg_mr(struct ibv_pd *pd, void *addr, size_t length, unsigned int access,
 #define ibv_reg_mr(pd, addr, length, access)                                   \
        __ibv_reg_mr(pd, addr, length, access,                                 \
                     __builtin_constant_p(                                     \
-                            ((access) & IBV_ACCESS_OPTIONAL_RANGE) == 0))
+                            ((int)(access) & IBV_ACCESS_OPTIONAL_RANGE) == 0))
 
 /**
  * ibv_reg_mr_iova - Register a memory region with a virtual offset
--

2.40.1

#10 lore raw
Quoted 3 lines · Daniel Vacek

Bump.

Was this forgotten or overlooked?

No, it just has to be processed manually if it is not a github PR..

Jason

maintainer Applied
#11 lore raw
In reply to Daniel Vacek
Quoted 5 lines · Daniel Vacek

Our customer reported the below warning whe using Clang v16.0.4 and C++20, on a code that includes the header "/usr/include/infiniband/verbs.h":

error: bitwise operation between different enumeration types ('ibv_access_flags' and 'ib_uverbs_access_flags') is deprecated [-Werror,-Wdeprecated-enum-enum-conversion]

Quoted 8 lines
                mem->mr = ibv_reg_mr(dev->pd, (void*)start, len, IBV_ACCESS_LOCAL_WRITE);
                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/infiniband/verbs.h:2514:19: note: expanded from macro 'ibv_reg_mr'
                             ((access) & IBV_ACCESS_OPTIONAL_RANGE) == 0))
                              ~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~

1 error generated.

[...]

Applied, thanks!

[1/1] verbs: fix compilation warning with C++20

      https://git.kernel.org/rdma/rdma/c/9e5ccbfdd208a1

Best regards,

Signature · 1 line
Leon Romanovsky <[email protected]>
#12 lore raw
Quoted 14 lines · Leon Romanovsky
Quoted 12 lines · Daniel Vacek

Our customer reported the below warning whe using Clang v16.0.4 and C++20, on a code that includes the header "/usr/include/infiniband/verbs.h":

error: bitwise operation between different enumeration types ('ibv_access_flags' and 'ib_uverbs_access_flags') is deprecated [-Werror,-Wdeprecated-enum-enum-conversion]

                mem->mr = ibv_reg_mr(dev->pd, (void*)start, len, IBV_ACCESS_LOCAL_WRITE);
                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/infiniband/verbs.h:2514:19: note: expanded from macro 'ibv_reg_mr'
                             ((access) & IBV_ACCESS_OPTIONAL_RANGE) == 0))
                              ~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~

1 error generated.

Quoted 6 lines
Quoted 1 line

[...]

Applied, thanks!

[1/1] verbs: fix compilation warning with C++20

      https://git.kernel.org/rdma/rdma/c/9e5ccbfdd208a1

The more accurate link is https://github.com/linux-rdma/rdma-core/pull/1367

Thanks

Quoted 4 lines

Best regards,

Signature · 1 line
Leon Romanovsky <[email protected]>