verbs: fix compilation warning with C++20
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
@@ -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
@@ -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
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
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
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
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
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
PATCH v2 1/1 verbs: fix compilation warning with C++20
In reply to Daniel VacekOur 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
@@ -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
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.
Reported-by Rogerio Moraes <[email protected]>Signed-off-by Daniel Vacek <[email protected]>--- libibverbs/verbs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)libibverbs/verbs.h +1
-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
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.Reported-by Rogerio Moraes <[email protected]>Signed-off-by Daniel Vacek <[email protected]>--- libibverbs/verbs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)libibverbs/verbs.h index renamed from libibverbs/verbs.h +0
-0
03a7a2a7..ed9aed21100644libibverbs/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
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.
Reported-by Rogerio Moraes <[email protected]>Signed-off-by Daniel Vacek <[email protected]>--- libibverbs/verbs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)libibverbs/verbs.h +1
-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
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
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]>
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]>