IB/mlx4: Avoid implicit enumerated type conversion
PATCH 1/1 IB/mlx4: Avoid implicit enumerated type conversion
Clang warns when one enumerated type is implicitly converted to another.
drivers/infiniband/hw/mlx4/mad.c:1811:41: warning: implicit conversion from enumeration type 'enum mlx4_ib_qp_flags' to different enumeration type 'enum ib_qp_create_flags' [-Wenum-conversion]
qp_init_attr.init_attr.create_flags = MLX4_IB_SRIOV_TUNNEL_QP;
~ ^~~~~~~~~~~~~~~~~~~~~~~drivers/infiniband/hw/mlx4/mad.c:1819:41: warning: implicit conversion from enumeration type 'enum mlx4_ib_qp_flags' to different enumeration type 'enum ib_qp_create_flags' [-Wenum-conversion]
qp_init_attr.init_attr.create_flags = MLX4_IB_SRIOV_SQP;
~ ^~~~~~~~~~~~~~~~~The type mlx4_ib_qp_flags explicitly provides supplemental values to the type ib_qp_create_flags. Make that clear to Clang by changing the create_flags type to u32.
--- include/rdma/ib_verbs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/rdma/ib_verbs.h +1 -1
@@ -1149,7 +1149,7 @@ struct ib_qp_init_attr {struct ib_qp_cap cap;enum ib_sig_type sq_sig_type;enum ib_qp_type qp_type; -enum ib_qp_create_flags create_flags; +u32 create_flags;/* * Only needed for special QP types, or when using the RW API.
Signature · 1 line
2.19.0
Quoted 30 lines · Nathan Chancellor
Clang warns when one enumerated type is implicitly converted to another.
drivers/infiniband/hw/mlx4/mad.c:1811:41: warning: implicit conversion from enumeration type 'enummlx4_ib_qp_flags' to different enumeration type 'enumib_qp_create_flags' [-Wenum-conversion]qp_init_attr.init_attr.create_flags = MLX4_IB_SRIOV_TUNNEL_QP; ~ ^~~~~~~~~~~~~~~~~~~~~~~
drivers/infiniband/hw/mlx4/mad.c:1819:41: warning: implicit conversion from enumeration type 'enummlx4_ib_qp_flags' to different enumeration type 'enumib_qp_create_flags' [-Wenum-conversion]qp_init_attr.init_attr.create_flags = MLX4_IB_SRIOV_SQP; ~ ^~~~~~~~~~~~~~~~~The type
mlx4_ib_qp_flagsexplicitly provides supplemental values to the typeib_qp_create_flags. Make that clear to Clang by changing thecreate_flagstype to u32.Reported-by Nick Desaulniers <[email protected]>Signed-off-by Nathan Chancellor <[email protected]>--- include/rdma/ib_verbs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/rdma/ib_verbs.h +0
-0
include/rdma/ib_verbs.h struct ib_qp_init_attr { · line 1152
Quoted 5 lines
include/rdma/ib_verbs.h +1
-1@@ -1149,7 +1149,7 @@ struct ib_qp_init_attr {struct ib_qp_cap cap;enum ib_sig_type sq_sig_type;enum ib_qp_type qp_type; -enum ib_qp_create_flags create_flags; +u32 create_flags;
I think it might be better to just have explicit casts at the assignment. What do the maintainers think?
Quoted 6 lines
include/rdma/ib_verbs.h +0
-1/* * Only needed for special QP types, or when using the RW API. -- 2.19.0
Signature · 2 lines
Thanks, ~Nick Desaulniers
Quoted 27 lines · Nick Desaulniers
Quoted 25 lines · Nathan Chancellor
Clang warns when one enumerated type is implicitly converted to another.
drivers/infiniband/hw/mlx4/mad.c:1811:41: warning: implicit conversion from enumeration type 'enummlx4_ib_qp_flags' to different enumeration type 'enumib_qp_create_flags' [-Wenum-conversion]qp_init_attr.init_attr.create_flags = MLX4_IB_SRIOV_TUNNEL_QP; ~ ^~~~~~~~~~~~~~~~~~~~~~~
drivers/infiniband/hw/mlx4/mad.c:1819:41: warning: implicit conversion from enumeration type 'enummlx4_ib_qp_flags' to different enumeration type 'enumib_qp_create_flags' [-Wenum-conversion]qp_init_attr.init_attr.create_flags = MLX4_IB_SRIOV_SQP; ~ ^~~~~~~~~~~~~~~~~The type
mlx4_ib_qp_flagsexplicitly provides supplemental values to the typeib_qp_create_flags. Make that clear to Clang by changing thecreate_flagstype to u32.Reported-by Nick Desaulniers <[email protected]>Signed-off-by Nathan Chancellor <[email protected]>--- include/rdma/ib_verbs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 14 lines
include/rdma/ib_verbs.h struct ib_qp_init_attr { · line 1152
Quoted 10 lines
include/rdma/ib_verbs.h +1
-1@@ -1149,7 +1149,7 @@ struct ib_qp_init_attr {struct ib_qp_cap cap;enum ib_sig_type sq_sig_type;enum ib_qp_type qp_type; -enum ib_qp_create_flags create_flags; +u32 create_flags;I think it might be better to just have explicit casts at the assignment. What do the maintainers think?
That's fine with me, I tend to explicitly cast if it is only one location but it certainly makes sense in this case as well. I'll wait for the maintainers to weigh in before sending a v2.
Thanks for the review,
Nathan
Quoted 11 lines
Quoted 6 lines
include/rdma/ib_verbs.h +0
-1/* * Only needed for special QP types, or when using the RW API. -- 2.19.0
Signature · 2 lines
Thanks, ~Nick Desaulniers
Quoted 44 lines · Nathan Chancellor
Quoted 27 lines · Nick Desaulniers
Quoted 25 lines · Nathan Chancellor
Clang warns when one enumerated type is implicitly converted to another.
drivers/infiniband/hw/mlx4/mad.c:1811:41: warning: implicit conversion from enumeration type 'enummlx4_ib_qp_flags' to different enumeration type 'enumib_qp_create_flags' [-Wenum-conversion]qp_init_attr.init_attr.create_flags = MLX4_IB_SRIOV_TUNNEL_QP; ~ ^~~~~~~~~~~~~~~~~~~~~~~
drivers/infiniband/hw/mlx4/mad.c:1819:41: warning: implicit conversion from enumeration type 'enummlx4_ib_qp_flags' to different enumeration type 'enumib_qp_create_flags' [-Wenum-conversion]qp_init_attr.init_attr.create_flags = MLX4_IB_SRIOV_SQP; ~ ^~~~~~~~~~~~~~~~~The type
mlx4_ib_qp_flagsexplicitly provides supplemental values to the typeib_qp_create_flags. Make that clear to Clang by changing thecreate_flagstype to u32.Reported-by Nick Desaulniers <[email protected]>Signed-off-by Nathan Chancellor <[email protected]>--- include/rdma/ib_verbs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Quoted 14 lines
include/rdma/ib_verbs.h struct ib_qp_init_attr { · line 1152
Quoted 10 lines
include/rdma/ib_verbs.h +1
-1@@ -1149,7 +1149,7 @@ struct ib_qp_init_attr {struct ib_qp_cap cap;enum ib_sig_type sq_sig_type;enum ib_qp_type qp_type; -enum ib_qp_create_flags create_flags; +u32 create_flags;I think it might be better to just have explicit casts at the assignment. What do the maintainers think?
Quoted 3 lines
That's fine with me, I tend to explicitly cast if it is only one location but it certainly makes sense in this case as well. I'll wait for the maintainers to weigh in before sending a v2.
Yeah, I mean my opinion on this might seem arbitrary, but based on the pattern and the comment in ib_qp_create_flags, those enum values are reserved to be "subclassed" in a sense, so they should always be in sync or this code will have bigger problems.
Quoted 15 lines
Thanks for the review,
NathanQuoted 11 lines
Quoted 6 lines
include/rdma/ib_verbs.h +0
-1/* * Only needed for special QP types, or when using the RW API. -- 2.19.0
--
Thanks,
~Nick Desaulniers
Signature · 2 lines
Thanks, ~Nick Desaulniers
Quoted 44 lines · Nick Desaulniers
Quoted 42 lines · Nathan Chancellor
Quoted 39 lines · Nick Desaulniers
Quoted 28 lines · Nathan Chancellor
Clang warns when one enumerated type is implicitly converted to another.
drivers/infiniband/hw/mlx4/mad.c:1811:41: warning: implicit conversion from enumeration type 'enummlx4_ib_qp_flags' to different enumeration type 'enumib_qp_create_flags' [-Wenum-conversion]qp_init_attr.init_attr.create_flags = MLX4_IB_SRIOV_TUNNEL_QP; ~ ^~~~~~~~~~~~~~~~~~~~~~~
drivers/infiniband/hw/mlx4/mad.c:1819:41: warning: implicit conversion from enumeration type 'enummlx4_ib_qp_flags' to different enumeration type 'enumib_qp_create_flags' [-Wenum-conversion]qp_init_attr.init_attr.create_flags = MLX4_IB_SRIOV_SQP; ~ ^~~~~~~~~~~~~~~~~The type
mlx4_ib_qp_flagsexplicitly provides supplemental values to the typeib_qp_create_flags. Make that clear to Clang by changing thecreate_flagstype to u32.Reported-by Nick Desaulniers <[email protected]>Signed-off-by Nathan Chancellor <[email protected]>include/rdma/ib_verbs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/rdma/ib_verbs.h +1
-0+++ b/include/rdma/ib_verbs.hinclude/rdma/ib_verbs.h struct ib_qp_init_attr { · line 1152
Quoted 5 lines
include/rdma/ib_verbs.h +1
-1@@ -1149,7 +1149,7 @@ struct ib_qp_init_attr {struct ib_qp_cap cap;enum ib_sig_type sq_sig_type;enum ib_qp_type qp_type; -enum ib_qp_create_flags create_flags; +u32 create_flags;I think it might be better to just have explicit casts at the assignment. What do the maintainers think?
Quoted 8 lines
Quoted 3 lines
That's fine with me, I tend to explicitly cast if it is only one location but it certainly makes sense in this case as well. I'll wait for the maintainers to weigh in before sending a v2.
Yeah, I mean my opinion on this might seem arbitrary, but based on the pattern and the comment in
ib_qp_create_flags, those enum values are reserved to be "subclassed" in a sense, so they should always be in sync or this code will have bigger problems.
One should not use an 'enum' type name for bitfield storage, as once you start or'ing things together the values no longer fall on the enum. Some compilers and tools even give warnings in this case, ie
enum x foo = X_A | X_B;
Is an assignment from 'int' to an 'enum x' with an implicit cast.
For this reason, usually bitfield enum declarations should be anonymous.
Jason
Quoted 58 lines · Jason Gunthorpe
Quoted 44 lines · Nick Desaulniers
Quoted 42 lines · Nathan Chancellor
Quoted 39 lines · Nick Desaulniers
Quoted 28 lines · Nathan Chancellor
Clang warns when one enumerated type is implicitly converted to another.
drivers/infiniband/hw/mlx4/mad.c:1811:41: warning: implicit conversion from enumeration type 'enummlx4_ib_qp_flags' to different enumeration type 'enumib_qp_create_flags' [-Wenum-conversion]qp_init_attr.init_attr.create_flags = MLX4_IB_SRIOV_TUNNEL_QP; ~ ^~~~~~~~~~~~~~~~~~~~~~~
drivers/infiniband/hw/mlx4/mad.c:1819:41: warning: implicit conversion from enumeration type 'enummlx4_ib_qp_flags' to different enumeration type 'enumib_qp_create_flags' [-Wenum-conversion]qp_init_attr.init_attr.create_flags = MLX4_IB_SRIOV_SQP; ~ ^~~~~~~~~~~~~~~~~The type
mlx4_ib_qp_flagsexplicitly provides supplemental values to the typeib_qp_create_flags. Make that clear to Clang by changing thecreate_flagstype to u32.Reported-by Nick Desaulniers <[email protected]>Signed-off-by Nathan Chancellor <[email protected]>include/rdma/ib_verbs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/rdma/ib_verbs.h +1
-0+++ b/include/rdma/ib_verbs.hinclude/rdma/ib_verbs.h struct ib_qp_init_attr { · line 1152
Quoted 5 lines
include/rdma/ib_verbs.h +1
-1@@ -1149,7 +1149,7 @@ struct ib_qp_init_attr {struct ib_qp_cap cap;enum ib_sig_type sq_sig_type;enum ib_qp_type qp_type; -enum ib_qp_create_flags create_flags; +u32 create_flags;I think it might be better to just have explicit casts at the assignment. What do the maintainers think?
Quoted 8 lines
Quoted 3 lines
That's fine with me, I tend to explicitly cast if it is only one location but it certainly makes sense in this case as well. I'll wait for the maintainers to weigh in before sending a v2.
Yeah, I mean my opinion on this might seem arbitrary, but based on the pattern and the comment in
ib_qp_create_flags, those enum values are reserved to be "subclassed" in a sense, so they should always be in sync or this code will have bigger problems.One should not use an 'enum' type name for bitfield storage, as once you start or'ing things together the values no longer fall on the enum. Some compilers and tools even give warnings in this case, ie
Quoted 8 lines
enum x foo = X_A | X_B;Is an assignment from 'int' to an 'enum x' with an implicit cast.
For this reason, usually bitfield enum declarations should be anonymous.
Jason
Hi Jason,
I apologize for not understanding but how should I adjust my patch so that it is acceptable? Do you want the explicit casts like Nick suggested?
Thanks for the comments,
Nathan
Quoted 66 lines · Nathan Chancellor
Quoted 65 lines · Jason Gunthorpe
Quoted 44 lines · Nick Desaulniers
Quoted 42 lines · Nathan Chancellor
Quoted 39 lines · Nick Desaulniers
Quoted 28 lines · Nathan Chancellor
Clang warns when one enumerated type is implicitly converted to another.
drivers/infiniband/hw/mlx4/mad.c:1811:41: warning: implicit conversion from enumeration type 'enummlx4_ib_qp_flags' to different enumeration type 'enumib_qp_create_flags' [-Wenum-conversion]qp_init_attr.init_attr.create_flags = MLX4_IB_SRIOV_TUNNEL_QP; ~ ^~~~~~~~~~~~~~~~~~~~~~~
drivers/infiniband/hw/mlx4/mad.c:1819:41: warning: implicit conversion from enumeration type 'enummlx4_ib_qp_flags' to different enumeration type 'enumib_qp_create_flags' [-Wenum-conversion]qp_init_attr.init_attr.create_flags = MLX4_IB_SRIOV_SQP; ~ ^~~~~~~~~~~~~~~~~The type
mlx4_ib_qp_flagsexplicitly provides supplemental values to the typeib_qp_create_flags. Make that clear to Clang by changing thecreate_flagstype to u32.Reported-by Nick Desaulniers <[email protected]>Signed-off-by Nathan Chancellor <[email protected]>include/rdma/ib_verbs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/rdma/ib_verbs.h +1
-0+++ b/include/rdma/ib_verbs.hinclude/rdma/ib_verbs.h struct ib_qp_init_attr { · line 1152
Quoted 5 lines
include/rdma/ib_verbs.h +1
-1@@ -1149,7 +1149,7 @@ struct ib_qp_init_attr {struct ib_qp_cap cap;enum ib_sig_type sq_sig_type;enum ib_qp_type qp_type; -enum ib_qp_create_flags create_flags; +u32 create_flags;I think it might be better to just have explicit casts at the assignment. What do the maintainers think?
Quoted 8 lines
Quoted 3 lines
That's fine with me, I tend to explicitly cast if it is only one location but it certainly makes sense in this case as well. I'll wait for the maintainers to weigh in before sending a v2.
Yeah, I mean my opinion on this might seem arbitrary, but based on the pattern and the comment in
ib_qp_create_flags, those enum values are reserved to be "subclassed" in a sense, so they should always be in sync or this code will have bigger problems.One should not use an 'enum' type name for bitfield storage, as once you start or'ing things together the values no longer fall on the enum. Some compilers and tools even give warnings in this case, ie
enum x foo = X_A | X_B;Is an assignment from 'int' to an 'enum x' with an implicit cast.
For this reason, usually bitfield enum declarations should be anonymous.
Quoted 7 lines
Quoted 1 line
Jason
Hi Jason,
I apologize for not understanding but how should I adjust my patch so that it is acceptable? Do you want the explicit casts like Nick suggested?
No, I think your original patch is fine, I was waiting to see if you or Nick disagreed with my assessment on bitfields..
Jason
Quoted 70 lines · Jason Gunthorpe
Quoted 68 lines · Nathan Chancellor
Quoted 66 lines · Jason Gunthorpe
Quoted 44 lines · Nick Desaulniers
Quoted 42 lines · Nathan Chancellor
Quoted 39 lines · Nick Desaulniers
Quoted 28 lines · Nathan Chancellor
Clang warns when one enumerated type is implicitly converted to another.
drivers/infiniband/hw/mlx4/mad.c:1811:41: warning: implicit conversion from enumeration type 'enummlx4_ib_qp_flags' to different enumeration type 'enumib_qp_create_flags' [-Wenum-conversion]qp_init_attr.init_attr.create_flags = MLX4_IB_SRIOV_TUNNEL_QP; ~ ^~~~~~~~~~~~~~~~~~~~~~~
drivers/infiniband/hw/mlx4/mad.c:1819:41: warning: implicit conversion from enumeration type 'enummlx4_ib_qp_flags' to different enumeration type 'enumib_qp_create_flags' [-Wenum-conversion]qp_init_attr.init_attr.create_flags = MLX4_IB_SRIOV_SQP; ~ ^~~~~~~~~~~~~~~~~The type
mlx4_ib_qp_flagsexplicitly provides supplemental values to the typeib_qp_create_flags. Make that clear to Clang by changing thecreate_flagstype to u32.Reported-by Nick Desaulniers <[email protected]>Signed-off-by Nathan Chancellor <[email protected]>include/rdma/ib_verbs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/rdma/ib_verbs.h +1
-0+++ b/include/rdma/ib_verbs.hinclude/rdma/ib_verbs.h struct ib_qp_init_attr { · line 1152
Quoted 5 lines
include/rdma/ib_verbs.h +1
-1@@ -1149,7 +1149,7 @@ struct ib_qp_init_attr {struct ib_qp_cap cap;enum ib_sig_type sq_sig_type;enum ib_qp_type qp_type; -enum ib_qp_create_flags create_flags; +u32 create_flags;I think it might be better to just have explicit casts at the assignment. What do the maintainers think?
Quoted 8 lines
Quoted 3 lines
That's fine with me, I tend to explicitly cast if it is only one location but it certainly makes sense in this case as well. I'll wait for the maintainers to weigh in before sending a v2.
Yeah, I mean my opinion on this might seem arbitrary, but based on the pattern and the comment in
ib_qp_create_flags, those enum values are reserved to be "subclassed" in a sense, so they should always be in sync or this code will have bigger problems.One should not use an 'enum' type name for bitfield storage, as once you start or'ing things together the values no longer fall on the enum. Some compilers and tools even give warnings in this case, ie
enum x foo = X_A | X_B;Is an assignment from 'int' to an 'enum x' with an implicit cast.
For this reason, usually bitfield enum declarations should be anonymous.
Jason
Quoted 8 lines
Quoted 5 lines
Hi Jason,
I apologize for not understanding but how should I adjust my patch so that it is acceptable? Do you want the explicit casts like Nick suggested?
No, I think your original patch is fine, I was waiting to see if you or Nick disagreed with my assessment on bitfields..
It wasn't clear to me whether you were ack'ing or nack'ing the patch. If we don't change the patch to explicit casts, shouldn't the change be to make create_flags an int? (note: signedness)
Signature · 2 lines
Thanks, ~Nick Desaulniers
Quoted 77 lines · Nick Desaulniers
Quoted 76 lines · Jason Gunthorpe
Quoted 73 lines · Nathan Chancellor
Quoted 58 lines · Jason Gunthorpe
Quoted 44 lines · Nick Desaulniers
Quoted 42 lines · Nathan Chancellor
Quoted 39 lines · Nick Desaulniers
Quoted 28 lines · Nathan Chancellor
Clang warns when one enumerated type is implicitly converted to another.
drivers/infiniband/hw/mlx4/mad.c:1811:41: warning: implicit conversion from enumeration type 'enummlx4_ib_qp_flags' to different enumeration type 'enumib_qp_create_flags' [-Wenum-conversion]qp_init_attr.init_attr.create_flags = MLX4_IB_SRIOV_TUNNEL_QP; ~ ^~~~~~~~~~~~~~~~~~~~~~~
drivers/infiniband/hw/mlx4/mad.c:1819:41: warning: implicit conversion from enumeration type 'enummlx4_ib_qp_flags' to different enumeration type 'enumib_qp_create_flags' [-Wenum-conversion]qp_init_attr.init_attr.create_flags = MLX4_IB_SRIOV_SQP; ~ ^~~~~~~~~~~~~~~~~The type
mlx4_ib_qp_flagsexplicitly provides supplemental values to the typeib_qp_create_flags. Make that clear to Clang by changing thecreate_flagstype to u32.Reported-by Nick Desaulniers <[email protected]>Signed-off-by Nathan Chancellor <[email protected]>include/rdma/ib_verbs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/rdma/ib_verbs.h +1
-0+++ b/include/rdma/ib_verbs.hinclude/rdma/ib_verbs.h struct ib_qp_init_attr { · line 1152
Quoted 5 lines
include/rdma/ib_verbs.h +1
-1@@ -1149,7 +1149,7 @@ struct ib_qp_init_attr {struct ib_qp_cap cap;enum ib_sig_type sq_sig_type;enum ib_qp_type qp_type; -enum ib_qp_create_flags create_flags; +u32 create_flags;I think it might be better to just have explicit casts at the assignment. What do the maintainers think?
Quoted 8 lines
Quoted 3 lines
That's fine with me, I tend to explicitly cast if it is only one location but it certainly makes sense in this case as well. I'll wait for the maintainers to weigh in before sending a v2.
Yeah, I mean my opinion on this might seem arbitrary, but based on the pattern and the comment in
ib_qp_create_flags, those enum values are reserved to be "subclassed" in a sense, so they should always be in sync or this code will have bigger problems.One should not use an 'enum' type name for bitfield storage, as once you start or'ing things together the values no longer fall on the enum. Some compilers and tools even give warnings in this case, ie
Quoted 8 lines
enum x foo = X_A | X_B;Is an assignment from 'int' to an 'enum x' with an implicit cast.
For this reason, usually bitfield enum declarations should be anonymous.
Jason
Hi Jason,
I apologize for not understanding but how should I adjust my patch so that it is acceptable? Do you want the explicit casts like Nick suggested?
Quoted 10 lines
Quoted 2 lines
No, I think your original patch is fine, I was waiting to see if you or Nick disagreed with my assessment on bitfields..
It wasn't clear to me whether you were ack'ing or nack'ing the patch. If we don't change the patch to explicit casts, shouldn't the change be to make
create_flagsan int? (note: signedness)Signature · 2 lines
Thanks, ~Nick Desaulniers
Neither ib_qp_create_flags nor mlx4_ib_qp_flags have negative values, is signedness necessary?
Nathan
Quoted 86 lines · Nathan Chancellor
Quoted 84 lines · Nick Desaulniers
Quoted 70 lines · Jason Gunthorpe
Quoted 68 lines · Nathan Chancellor
Quoted 66 lines · Jason Gunthorpe
Quoted 44 lines · Nick Desaulniers
Quoted 42 lines · Nathan Chancellor
Quoted 39 lines · Nick Desaulniers
Quoted 28 lines · Nathan Chancellor
Clang warns when one enumerated type is implicitly converted to another.
drivers/infiniband/hw/mlx4/mad.c:1811:41: warning: implicit conversion from enumeration type 'enummlx4_ib_qp_flags' to different enumeration type 'enumib_qp_create_flags' [-Wenum-conversion]qp_init_attr.init_attr.create_flags = MLX4_IB_SRIOV_TUNNEL_QP; ~ ^~~~~~~~~~~~~~~~~~~~~~~
drivers/infiniband/hw/mlx4/mad.c:1819:41: warning: implicit conversion from enumeration type 'enummlx4_ib_qp_flags' to different enumeration type 'enumib_qp_create_flags' [-Wenum-conversion]qp_init_attr.init_attr.create_flags = MLX4_IB_SRIOV_SQP; ~ ^~~~~~~~~~~~~~~~~The type
mlx4_ib_qp_flagsexplicitly provides supplemental values to the typeib_qp_create_flags. Make that clear to Clang by changing thecreate_flagstype to u32.Reported-by Nick Desaulniers <[email protected]>Signed-off-by Nathan Chancellor <[email protected]>include/rdma/ib_verbs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/rdma/ib_verbs.h +1
-0+++ b/include/rdma/ib_verbs.hinclude/rdma/ib_verbs.h struct ib_qp_init_attr { · line 1152
Quoted 5 lines
include/rdma/ib_verbs.h +1
-1@@ -1149,7 +1149,7 @@ struct ib_qp_init_attr {struct ib_qp_cap cap;enum ib_sig_type sq_sig_type;enum ib_qp_type qp_type; -enum ib_qp_create_flags create_flags; +u32 create_flags;I think it might be better to just have explicit casts at the assignment. What do the maintainers think?
Quoted 8 lines
Quoted 3 lines
That's fine with me, I tend to explicitly cast if it is only one location but it certainly makes sense in this case as well. I'll wait for the maintainers to weigh in before sending a v2.
Yeah, I mean my opinion on this might seem arbitrary, but based on the pattern and the comment in
ib_qp_create_flags, those enum values are reserved to be "subclassed" in a sense, so they should always be in sync or this code will have bigger problems.One should not use an 'enum' type name for bitfield storage, as once you start or'ing things together the values no longer fall on the enum. Some compilers and tools even give warnings in this case, ie
enum x foo = X_A | X_B;Is an assignment from 'int' to an 'enum x' with an implicit cast.
For this reason, usually bitfield enum declarations should be anonymous.
Jason
Quoted 8 lines
Quoted 5 lines
Hi Jason,
I apologize for not understanding but how should I adjust my patch so that it is acceptable? Do you want the explicit casts like Nick suggested?
No, I think your original patch is fine, I was waiting to see if you or Nick disagreed with my assessment on bitfields..
It wasn't clear to me whether you were ack'ing or nack'ing the patch. If we don't change the patch to explicit casts, shouldn't the change be to make
create_flagsan int? (note: signedness)
Quoted 6 lines
Quoted 3 lines
--
Thanks,
~Nick DesaulniersNeither
ib_qp_create_flagsnormlx4_ib_qp_flagshave negative values, is signedness necessary?
enums are by default restricted to the range of ints. It's not right to tie these "anonymous enums" to a specific width and signedness other than int.
Signature · 2 lines
Thanks, ~Nick Desaulniers
Quoted 92 lines · Nick Desaulniers
Quoted 90 lines · Nathan Chancellor
Quoted 87 lines · Nick Desaulniers
Quoted 70 lines · Jason Gunthorpe
Quoted 68 lines · Nathan Chancellor
Quoted 66 lines · Jason Gunthorpe
Quoted 44 lines · Nick Desaulniers
Quoted 42 lines · Nathan Chancellor
Quoted 39 lines · Nick Desaulniers
Quoted 28 lines · Nathan Chancellor
Clang warns when one enumerated type is implicitly converted to another.
drivers/infiniband/hw/mlx4/mad.c:1811:41: warning: implicit conversion from enumeration type 'enummlx4_ib_qp_flags' to different enumeration type 'enumib_qp_create_flags' [-Wenum-conversion]qp_init_attr.init_attr.create_flags = MLX4_IB_SRIOV_TUNNEL_QP; ~ ^~~~~~~~~~~~~~~~~~~~~~~
drivers/infiniband/hw/mlx4/mad.c:1819:41: warning: implicit conversion from enumeration type 'enummlx4_ib_qp_flags' to different enumeration type 'enumib_qp_create_flags' [-Wenum-conversion]qp_init_attr.init_attr.create_flags = MLX4_IB_SRIOV_SQP; ~ ^~~~~~~~~~~~~~~~~The type
mlx4_ib_qp_flagsexplicitly provides supplemental values to the typeib_qp_create_flags. Make that clear to Clang by changing thecreate_flagstype to u32.Reported-by Nick Desaulniers <[email protected]>Signed-off-by Nathan Chancellor <[email protected]>include/rdma/ib_verbs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/rdma/ib_verbs.h +1
-0+++ b/include/rdma/ib_verbs.hinclude/rdma/ib_verbs.h struct ib_qp_init_attr { · line 1152
Quoted 5 lines
include/rdma/ib_verbs.h +1
-1@@ -1149,7 +1149,7 @@ struct ib_qp_init_attr {struct ib_qp_cap cap;enum ib_sig_type sq_sig_type;enum ib_qp_type qp_type; -enum ib_qp_create_flags create_flags; +u32 create_flags;I think it might be better to just have explicit casts at the assignment. What do the maintainers think?
Quoted 8 lines
Quoted 3 lines
That's fine with me, I tend to explicitly cast if it is only one location but it certainly makes sense in this case as well. I'll wait for the maintainers to weigh in before sending a v2.
Yeah, I mean my opinion on this might seem arbitrary, but based on the pattern and the comment in
ib_qp_create_flags, those enum values are reserved to be "subclassed" in a sense, so they should always be in sync or this code will have bigger problems.One should not use an 'enum' type name for bitfield storage, as once you start or'ing things together the values no longer fall on the enum. Some compilers and tools even give warnings in this case, ie
enum x foo = X_A | X_B;Is an assignment from 'int' to an 'enum x' with an implicit cast.
For this reason, usually bitfield enum declarations should be anonymous.
Jason
Quoted 8 lines
Quoted 5 lines
Hi Jason,
I apologize for not understanding but how should I adjust my patch so that it is acceptable? Do you want the explicit casts like Nick suggested?
No, I think your original patch is fine, I was waiting to see if you or Nick disagreed with my assessment on bitfields..
It wasn't clear to me whether you were ack'ing or nack'ing the patch. If we don't change the patch to explicit casts, shouldn't the change be to make
create_flagsan int? (note: signedness)--
Thanks,
~Nick Desaulniers
Quoted 10 lines
Quoted 2 lines
Neither
ib_qp_create_flagsnormlx4_ib_qp_flagshave negative values, is signedness necessary?enums are by default restricted to the range of ints. It's not right to tie these "anonymous enums" to a specific width and signedness other than int.
Signature · 2 lines
Thanks, ~Nick Desaulniers
Thanks for the clarification, I will go ahead and send a v2 now.
Nathan
Quoted 4 lines · Nick Desaulniers
Quoted 2 lines
Neither
ib_qp_create_flagsnormlx4_ib_qp_flagshave negative values, is signedness necessary?enums are by default restricted to the range of ints.
That's not quite right, the compiler sizes the enum to be able to fit the largest value contained within, today that is int, but if we added 1<<31, then it would become larger.
Values intended to hold bitfields should always be unsigned, so u32 is an appropriate for flags where the flags are defined in an enum.
Jason
Quoted 10 lines · Jason Gunthorpe
Quoted 4 lines · Nick Desaulniers
Quoted 2 lines
Neither
ib_qp_create_flagsnormlx4_ib_qp_flagshave negative values, is signedness necessary?enums are by default restricted to the range of ints.
That's not quite right, the compiler sizes the enum to be able to fit the largest value contained within, today that is int, but if we added 1<<31, then it would become larger.
Hi Jason,
Are you perhaps confusing C and C+-+-? For C+-+-, an enumeration whose underlying type is not fixed, the underlying type is an integral type that can represent all the enumerator values defined in the enumeration. For C however I think that enumeration values are restricted to what fits in an int.
Bart.
Quoted 13 lines · Bart Van Assche
Quoted 10 lines · Jason Gunthorpe
Quoted 4 lines · Nick Desaulniers
Quoted 2 lines
Neither
ib_qp_create_flagsnormlx4_ib_qp_flagshave negative values, is signedness necessary?enums are by default restricted to the range of ints.
That's not quite right, the compiler sizes the enum to be able to fit the largest value contained within, today that is int, but if we added 1<<31, then it would become larger.
Quoted 9 lines
Hi Jason,
Are you perhaps confusing C and C++? For C++, an enumeration whose underlying type is not fixed, the underlying type is an integral type that can represent all the enumerator values defined in the enumeration. For C however I think that enumeration values are restricted to what fits in an int.
Bart.
To quote the sacred texts (ANSIIISO9899-1990):
6.5.2.2 Enumeration specifiers
The expression that defines the value of an enumeration constant shall be an integral constant
expression that has a value representable as an int.
Signature · 2 lines
Thanks, ~Nick Desaulniers
Quoted 24 lines · Nick Desaulniers
Quoted 13 lines · Bart Van Assche
Quoted 10 lines · Jason Gunthorpe
Quoted 4 lines · Nick Desaulniers
Quoted 2 lines
Neither
ib_qp_create_flagsnormlx4_ib_qp_flagshave negative values, is signedness necessary?enums are by default restricted to the range of ints.
That's not quite right, the compiler sizes the enum to be able to fit the largest value contained within, today that is int, but if we added 1<<31, then it would become larger.
Quoted 9 lines
Hi Jason,
Are you perhaps confusing C and C++? For C++, an enumeration whose underlying type is not fixed, the underlying type is an integral type that can represent all the enumerator values defined in the enumeration. For C however I think that enumeration values are restricted to what fits in an int.
Bart.
Quoted 6 lines
To quote the sacred texts (ANSIIISO9899-1990):
6.5.2.2 Enumeration specifiers
The expression that defines the value of an enumeration constant shall be an integral constant
expression that has a value representable as an int.
This is the wrong part of the standard to quote it is talking about *enumeration constants* not the 'enum X' itself.
Anyhow, the standard is hard to read in this area, but reality is this:
#include <stdio.h>
enum a
{
A1 = 1,
A2 = 1ULL<<40,
};int main(int argc, const char *argv[])
{
printf("%zu\n", sizeof(enum a));
return 0;
}$ gcc -Wall -std=c11 test.c && ./a.out 8
I forget if this a common compiler extension, unclear standard, or was formally revised in C11 or what, but it is the real world the Linux kernel lives in.
It is even more confusing if you wonder what types A1 and A2 are!
Jason
Quoted 13 lines · Jason Gunthorpe
Anyhow, the standard is hard to read in this area, but reality is this:
#include <
stdio.h>>
enum a
{> A1 =1,A2 =1ULL<<40, };>int main(int argc, const char *argv[]
{>printf("%zu\n" sizeof(enum a));> return 0;>}>
$gcc -Wall -std=c11test.c&&./a.out
8
Quoted 5 lines
I forget if this a common compiler extension, unclear standard, or was formally revised in C11 or what, but it is the real world the Linux kernel lives in.
It is even more confusing if you wonder what types A1 and A2 are!
What's unfortunate is that gcc and sparse have different opinions about how to compile the above code. Even if gcc supports enumeration constants that exceed what fits in an int, sparse does not AFAIK.
Bart.
Quoted 33 lines · Jason Gunthorpe
Quoted 24 lines · Nick Desaulniers
Quoted 13 lines · Bart Van Assche
Quoted 10 lines · Jason Gunthorpe
Quoted 4 lines · Nick Desaulniers
Quoted 2 lines
Neither
ib_qp_create_flagsnormlx4_ib_qp_flagshave negative values, is signedness necessary?enums are by default restricted to the range of ints.
That's not quite right, the compiler sizes the enum to be able to fit the largest value contained within, today that is int, but if we added 1<<31, then it would become larger.
Quoted 9 lines
Hi Jason,
Are you perhaps confusing C and C++? For C++, an enumeration whose underlying type is not fixed, the underlying type is an integral type that can represent all the enumerator values defined in the enumeration. For C however I think that enumeration values are restricted to what fits in an int.
Bart.
Quoted 6 lines
To quote the sacred texts (ANSIIISO9899-1990):
6.5.2.2 Enumeration specifiers
The expression that defines the value of an enumeration constant shall be an integral constant
expression that has a value representable as an int.
Quoted 5 lines
This is the wrong part of the standard to quote it is talking about *enumeration constants* not the 'enum X' itself.
Anyhow, the standard is hard to read in this area, but reality is this:
You mean undefined behavior?
Quoted 18 lines
#include <
stdio.h>enum a
{ A1 = 1, A2 = 1ULL<<40, };int
main(int argc, const char *argv[]){ printf("%zu\n", sizeof(enum a)); return 0; }$ gcc -Wall -std=c11 test.c && ./a.out 8
Quoted 7 lines
I forget if this a common compiler extension, unclear standard, or was formally revised in C11 or what, but it is the real world the Linux kernel lives in.
It is even more confusing if you wonder what types A1 and A2 are!
Jason
This example is a strawman; we're talking about the minimum sizeof an enum when all initialized values are representable within an int, which is well defined behavior by the citation I cited earlier. The point is, unless you use __attribute__((packed)) on your enum, it will NEVER be *smaller* than an int for compilers and C standard that the Linux kernel cares about.
And if you're going to throw type safety out the window by converting values from one enum to another, for storage you MUST use an int (anything larger as in your example is undefined behavior).
I don't disagree with your point that values should be unsigned for bitwise operations, but it's not clean to reconcile that with converting values between different enums. I suggest explicit casts to unsigned types before bitwise operations.
Signature · 2 lines
Thanks, ~Nick Desaulniers
Quoted 34 lines · Nick Desaulniers
Quoted 33 lines · Jason Gunthorpe
Quoted 30 lines · Nick Desaulniers
Quoted 13 lines · Bart Van Assche
Quoted 10 lines · Jason Gunthorpe
Quoted 4 lines · Nick Desaulniers
Quoted 2 lines
Neither
ib_qp_create_flagsnormlx4_ib_qp_flagshave negative values, is signedness necessary?enums are by default restricted to the range of ints.
That's not quite right, the compiler sizes the enum to be able to fit the largest value contained within, today that is int, but if we added 1<<31, then it would become larger.
Quoted 9 lines
Hi Jason,
Are you perhaps confusing C and C++? For C++, an enumeration whose underlying type is not fixed, the underlying type is an integral type that can represent all the enumerator values defined in the enumeration. For C however I think that enumeration values are restricted to what fits in an int.
Bart.
To quote the sacred texts (ANSIIISO9899-1990):
6.5.2.2 Enumeration specifiers
The expression that defines the value of an enumeration constant shall be an integral constant
expression that has a value representable as an int.
Quoted 7 lines
Quoted 5 lines
This is the wrong part of the standard to quote it is talking about *enumeration constants* not the 'enum X' itself.
Anyhow, the standard is hard to read in this area, but reality is this:
You mean undefined behavior?
I think we call this an unstandardized compiler extension :)
Quoted 21 lines
Quoted 21 lines
#include <
stdio.h>enum a
{ A1 = 1, A2 = 1ULL<<40, };int
main(int argc, const char *argv[]){ printf("%zu\n", sizeof(enum a)); return 0; }$ gcc -Wall -std=c11 test.c && ./a.out 8I forget if this a common compiler extension, unclear standard, or was formally revised in C11 or what, but it is the real world the Linux kernel lives in.
Quoted 6 lines
Quoted 3 lines
It is even more confusing if you wonder what types A1 and A2 are!
Jason
This example is a strawman; we're talking about the minimum sizeof an enum when all initialized values are representable within an int,
Hmm? I said "the compiler sizes the enum to be able to fit the largest value contained within", which is correct for gnu89 mode.
It is not ISO C, it looks like it is a popular compiler extension that Linux relies on.
Quoted 3 lines
And if you're going to throw type safety out the window by converting values from one enum to another, for storage you MUST use an int (anything larger as in your example is undefined behavior).
No, that isn't right even without this extension, it is confusing, but the standard you quoted is talking about the type of the CONSTANT, not the enum. Ie this:
enum a {A1=1};
enum a val = A1;
int foo = val;Gives this warning:
t.c:10:17: warning: implicit conversion changes signedness: 'enum a' to 'int' [-Wsign-conversion]
The correct integral storage for that enum is 'unsigned int'.
There is another peice of standard talking about the type of the enum itself, and confoundingly it is a different type than the types of the constants.
C++ got this right, the type of the enum and the type of the constants are always the same and always sized to match the largest constant in the enum, and C++11 got this *really right* and allows the programmer to specify the underlying type of the enum and all of its constants.
No more subtle bugs with ~FOO because enum constant values have negative types!
Quoted 4 lines
I don't disagree with your point that values should be unsigned for bitwise operations, but it's not clean to reconcile that with converting values between different enums. I suggest explicit casts to unsigned types before bitwise operations.
Sometimes the casts are needed, particularly when using ~, but for | it is OK to have no casts, promotion rules work out OK.
But, again, this question was about the correct type to use when storing bitwise flags, and that type is u32/64 etc no matter if the constants are defined as enum constants or #defines values.
So the first patch was the right one! :)
Jason
PATCH v2 1/1 IB/mlx4: Avoid implicit enumerated type conversion
In reply to Nathan ChancellorClang warns when one enumerated type is implicitly converted to another.
drivers/infiniband/hw/mlx4/mad.c:1811:41: warning: implicit conversion from enumeration type 'enum mlx4_ib_qp_flags' to different enumeration type 'enum ib_qp_create_flags' [-Wenum-conversion]
qp_init_attr.init_attr.create_flags = MLX4_IB_SRIOV_TUNNEL_QP;
~ ^~~~~~~~~~~~~~~~~~~~~~~drivers/infiniband/hw/mlx4/mad.c:1819:41: warning: implicit conversion from enumeration type 'enum mlx4_ib_qp_flags' to different enumeration type 'enum ib_qp_create_flags' [-Wenum-conversion]
qp_init_attr.init_attr.create_flags = MLX4_IB_SRIOV_SQP;
~ ^~~~~~~~~~~~~~~~~The type mlx4_ib_qp_flags explicitly provides supplemental values to the type ib_qp_create_flags. Make that clear to Clang by changing the create_flags type to int.
---
v1 -> v2:
* Use int instead of u32 since enums are restricted to this range, as suggested by Nick.
include/rdma/ib_verbs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/rdma/ib_verbs.h +1 -1
@@ -1151,7 +1151,7 @@ struct ib_qp_init_attr {struct ib_qp_cap cap;enum ib_sig_type sq_sig_type;enum ib_qp_type qp_type; -enum ib_qp_create_flags create_flags; +int create_flags;/* * Only needed for special QP types, or when using the RW API.
Signature · 1 line
2.19.0
Quoted 19 lines · Nathan Chancellor
Clang warns when one enumerated type is implicitly converted to another.
drivers/infiniband/hw/mlx4/mad.c:1811:41: warning: implicit conversion from enumeration type 'enummlx4_ib_qp_flags' to different enumeration type 'enumib_qp_create_flags' [-Wenum-conversion]qp_init_attr.init_attr.create_flags = MLX4_IB_SRIOV_TUNNEL_QP; ~ ^~~~~~~~~~~~~~~~~~~~~~~
drivers/infiniband/hw/mlx4/mad.c:1819:41: warning: implicit conversion from enumeration type 'enummlx4_ib_qp_flags' to different enumeration type 'enumib_qp_create_flags' [-Wenum-conversion]qp_init_attr.init_attr.create_flags = MLX4_IB_SRIOV_SQP; ~ ^~~~~~~~~~~~~~~~~The type
mlx4_ib_qp_flagsexplicitly provides supplemental values to the typeib_qp_create_flags. Make that clear to Clang by changing thecreate_flagstype to int.
Quoted 8 lines
Reported-by Nick Desaulniers <[email protected]>Signed-off-by Nathan Chancellor <[email protected]>---
v1 -> v2:
* Use int instead of u32 since enums are restricted to this range, as suggested by Nick.
Thank you for making this change.
Quoted 20 lines
include/rdma/ib_verbs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/rdma/ib_verbs.h +1
-2@@ -1151,7 +1151,7 @@ struct ib_qp_init_attr {struct ib_qp_cap cap;enum ib_sig_type sq_sig_type;enum ib_qp_type qp_type; -enum ib_qp_create_flags create_flags; +int create_flags;/* * Only needed for special QP types, or when using the RW API. -- 2.19.0
Signature · 2 lines
Thanks, ~Nick Desaulniers
Jason Gunthorpe
AppliedQuoted 18 lines · Nathan Chancellor
Clang warns when one enumerated type is implicitly converted to another.
drivers/infiniband/hw/mlx4/mad.c:1811:41: warning: implicit conversion from enumeration type 'enummlx4_ib_qp_flags' to different enumeration type 'enumib_qp_create_flags' [-Wenum-conversion]qp_init_attr.init_attr.create_flags = MLX4_IB_SRIOV_TUNNEL_QP; ~ ^~~~~~~~~~~~~~~~~~~~~~~
drivers/infiniband/hw/mlx4/mad.c:1819:41: warning: implicit conversion from enumeration type 'enummlx4_ib_qp_flags' to different enumeration type 'enumib_qp_create_flags' [-Wenum-conversion]qp_init_attr.init_attr.create_flags = MLX4_IB_SRIOV_SQP; ~ ^~~~~~~~~~~~~~~~~The type
mlx4_ib_qp_flagsexplicitly provides supplemental values to the typeib_qp_create_flags. Make that clear to Clang by changing thecreate_flagstype to u32.
Quoted 5 lines
Reported-by Nick Desaulniers <[email protected]>Signed-off-by Nathan Chancellor <[email protected]>--- include/rdma/ib_verbs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Applied to for-next, thanks
BTW, how are you compiling with clang?
Jason
Quoted 26 lines · Jason Gunthorpe
Quoted 18 lines · Nathan Chancellor
Clang warns when one enumerated type is implicitly converted to another.
drivers/infiniband/hw/mlx4/mad.c:1811:41: warning: implicit conversion from enumeration type 'enummlx4_ib_qp_flags' to different enumeration type 'enumib_qp_create_flags' [-Wenum-conversion]qp_init_attr.init_attr.create_flags = MLX4_IB_SRIOV_TUNNEL_QP; ~ ^~~~~~~~~~~~~~~~~~~~~~~
drivers/infiniband/hw/mlx4/mad.c:1819:41: warning: implicit conversion from enumeration type 'enummlx4_ib_qp_flags' to different enumeration type 'enumib_qp_create_flags' [-Wenum-conversion]qp_init_attr.init_attr.create_flags = MLX4_IB_SRIOV_SQP; ~ ^~~~~~~~~~~~~~~~~The type
mlx4_ib_qp_flagsexplicitly provides supplemental values to the typeib_qp_create_flags. Make that clear to Clang by changing thecreate_flagstype to u32.Quoted 5 lines
Reported-by Nick Desaulniers <[email protected]>Signed-off-by Nathan Chancellor <[email protected]>--- include/rdma/ib_verbs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 3 lines
Applied to for-next, thanks
BTW, how are you compiling with clang?
https://github.com/ClangBuiltLinux/linux/wiki/Steps-for-compiling-the-kernel-with-Clang
try it out, let us know bugs you find here:
https://github.com/ClangBuiltLinux/linux/issues
Still looking into the case you pointed out earlier. I suspect the signedness of enums was undefined in c90, then defined as implementation specific in c99 (though I'm still researching that book report). Thanks for your insights!
Quoted 2 lines
Jason
Signature · 2 lines
Thanks, ~Nick Desaulniers
Quoted 26 lines · Nick Desaulniers
Quoted 25 lines · Jason Gunthorpe
Quoted 22 lines · Nathan Chancellor
Clang warns when one enumerated type is implicitly converted to another.
drivers/infiniband/hw/mlx4/mad.c:1811:41: warning: implicit conversion from enumeration type 'enummlx4_ib_qp_flags' to different enumeration type 'enumib_qp_create_flags' [-Wenum-conversion]qp_init_attr.init_attr.create_flags = MLX4_IB_SRIOV_TUNNEL_QP; ~ ^~~~~~~~~~~~~~~~~~~~~~~
drivers/infiniband/hw/mlx4/mad.c:1819:41: warning: implicit conversion from enumeration type 'enummlx4_ib_qp_flags' to different enumeration type 'enumib_qp_create_flags' [-Wenum-conversion]qp_init_attr.init_attr.create_flags = MLX4_IB_SRIOV_SQP; ~ ^~~~~~~~~~~~~~~~~The type
mlx4_ib_qp_flagsexplicitly provides supplemental values to the typeib_qp_create_flags. Make that clear to Clang by changing thecreate_flagstype to u32.Reported-by Nick Desaulniers <[email protected]>Signed-off-by Nathan Chancellor <[email protected]>include/rdma/ib_verbs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 7 lines
Quoted 3 lines
Applied to for-next, thanks
BTW, how are you compiling with clang?
https://github.com/ClangBuiltLinux/linux/wiki/Steps-for-compiling-the-kernel-with-Clang
try it out, let us know bugs you find here:
https://github.com/ClangBuiltLinux/linux/issues
Oh I see, you are doing ARM64!
Quoted 4 lines
Still looking into the case you pointed out earlier. I suspect the signedness of enums was undefined in c90, then defined as implementation specific in c99 (though I'm still researching that book report). Thanks for your insights!
C enums details are a topic that seems more confusing every time it gets brought up :(
Jason
Quoted 30 lines · Jason Gunthorpe
Quoted 28 lines · Nick Desaulniers
Quoted 27 lines · Jason Gunthorpe
Quoted 14 lines · Nathan Chancellor
Clang warns when one enumerated type is implicitly converted to another.
drivers/infiniband/hw/mlx4/mad.c:1811:41: warning: implicit conversion from enumeration type 'enummlx4_ib_qp_flags' to different enumeration type 'enumib_qp_create_flags' [-Wenum-conversion]qp_init_attr.init_attr.create_flags = MLX4_IB_SRIOV_TUNNEL_QP; ~ ^~~~~~~~~~~~~~~~~~~~~~~
drivers/infiniband/hw/mlx4/mad.c:1819:41: warning: implicit conversion from enumeration type 'enummlx4_ib_qp_flags' to different enumeration type 'enumib_qp_create_flags' [-Wenum-conversion]qp_init_attr.init_attr.create_flags = MLX4_IB_SRIOV_SQP; ~ ^~~~~~~~~~~~~~~~~Quoted 8 lines
The type
mlx4_ib_qp_flagsexplicitly provides supplemental values to the typeib_qp_create_flags. Make that clear to Clang by changing thecreate_flagstype to u32.Reported-by Nick Desaulniers <[email protected]>Signed-off-by Nathan Chancellor <[email protected]>include/rdma/ib_verbs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Applied to for-next, thanks
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
BTW, how are you compiling with clang?
https://github.com/ClangBuiltLinux/linux/wiki/Steps-for-compiling-the-kernel-with-Clang
try it out, let us know bugs you find here:
https://github.com/ClangBuiltLinux/linux/issuesOh I see, you are doing ARM64!
Well, it's the first arch I'm focusing on. X86_64 and ARM32 are also a priority. Open source contributors are filing bugs against powerpc, x86, and even risc-v. I'm helping them with code review or putting them in contact with the relevant parties.
We're going to talk more about this effort at Linux Plumbers Conference in November if you're going.
Quoted 10 lines
Quoted 5 lines
Still looking into the case you pointed out earlier. I suspect the signedness of enums was undefined in c90, then defined as implementation specific in c99 (though I'm still researching that book report). Thanks for your insights!
C enums details are a topic that seems more confusing every time it gets brought up :(
Jason
Signature · 2 lines
Thanks, ~Nick Desaulniers