Skip to content

Commit 4943c20

Browse files
r-barnesfacebook-github-bot
authored andcommitted
Fix enum math in verbs.h for CUDA C++20 upgrade via reversions and casts
Summary: Generated by running ``` hg backout D88882181 hg backout D89083275 hg backout D88911049 ``` and then adding explicit casts. `infiniband/verbs.h` caused C++20 compilation failures due to enum-enum math which could not simply be suppressed because it's a header file. D88882181 converted `enum` to constants to allow the math to work and because the enums themselves seemed suspect. This caused compilation to succeed with C++20 and unblock a number of broken tests. But it broke Rust! D89083275 and D88911049 fix Rust by artificially restoring the `enum` values. But that's a mess. Here we back out both D88882181 and D89083275 and D88911049. Doing so brings us back to a state where the following compilation error would arise: ``` buck-out/v2/gen/fbsource/third-party/rdma-core/stablev60/__ibverbs__/c01e142197f8fe04/buck-headers/infiniband/verbs.h:573:59: error: bitwise operation between different enumeration types ('(unnamed enum at buck-out/v2/gen/fbsource/third-party/rdma-core/stablev60/__ibverbs__/c01e142197f8fe04/buck-headers/infiniband/verbs.h:562:1)' and 'ibv_create_cq_wc_flags') is deprecated [-Werror,-Wdeprecated-anon-enum-enum-conversion] 573 | IBV_CREATE_CQ_SUP_WC_FLAGS = ((((((IBV_WC_STANDARD_FLAGS) | (IBV_WC_EX_WITH_COMPLETION_TIMESTAMP)) | (IBV_WC_EX_WITH_CVLAN)) | (IBV_WC_EX_WITH_FLOW_TAG)) | (IBV_WC_EX_WITH_TM_INFO)) | (IBV_WC_EX_WITH_COMPLETION_TIMESTAMP_WALLCLOCK)) | ~~~~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ``` This time we fix the error by adding explicit `(int)` casts to the affected Line 573. The result is code that: * Compiles with C++20 by explicitly suppressing the issue causing the compilation failure * Retains the enums so that builds with Rust work. Upstream PR: linux-rdma/rdma-core#1671 See discussion [here](https://fb.workplace.com/groups/rust.language/permalink/30268407786114448/). Reviewed By: peterdelevoryas Differential Revision: D89088011
1 parent 2c8aa89 commit 4943c20

File tree

1 file changed

+2
-56
lines changed

1 file changed

+2
-56
lines changed

rdmaxcel-sys/src/lib.rs

Lines changed: 2 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -15,68 +15,14 @@ mod inner {
1515
#![allow(non_snake_case)]
1616
#![allow(unused_attributes)]
1717
#[cfg(not(cargo))]
18+
use crate::ibv_wc_flags;
19+
#[cfg(not(cargo))]
1820
use crate::ibv_wc_opcode;
1921
#[cfg(not(cargo))]
2022
use crate::ibv_wc_status;
2123
#[cfg(cargo)]
2224
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
2325

24-
// Manually define ibv_wc_flags as a bitfield (bindgen can't generate it from static const)
25-
// Only needed in fbcode builds - OSS/cargo builds have bindgen generate these from enums
26-
#[cfg(not(cargo))]
27-
#[repr(transparent)]
28-
#[derive(Debug, Copy, Clone, PartialEq, Eq, Default)]
29-
pub struct ibv_wc_flags(pub u32);
30-
31-
#[cfg(not(cargo))]
32-
impl ibv_wc_flags {
33-
pub const IBV_WC_GRH: Self = Self(1 << 0);
34-
pub const IBV_WC_WITH_IMM: Self = Self(1 << 1);
35-
pub const IBV_WC_IP_CSUM_OK: Self = Self(1 << 2);
36-
pub const IBV_WC_WITH_INV: Self = Self(1 << 3);
37-
pub const IBV_WC_TM_SYNC_REQ: Self = Self(1 << 4);
38-
pub const IBV_WC_TM_MATCH: Self = Self(1 << 5);
39-
pub const IBV_WC_TM_DATA_VALID: Self = Self(1 << 6);
40-
}
41-
42-
#[cfg(not(cargo))]
43-
impl std::ops::BitAnd for ibv_wc_flags {
44-
type Output = Self;
45-
fn bitand(self, rhs: Self) -> Self {
46-
Self(self.0 & rhs.0)
47-
}
48-
}
49-
50-
// Manually define ibv_access_flags as a bitfield (bindgen can't generate it from static const)
51-
// Only needed in fbcode builds - OSS/cargo builds have bindgen generate these from enums
52-
#[cfg(not(cargo))]
53-
#[repr(transparent)]
54-
#[derive(Debug, Copy, Clone, PartialEq, Eq, Default)]
55-
pub struct ibv_access_flags(pub u32);
56-
57-
#[cfg(not(cargo))]
58-
impl ibv_access_flags {
59-
pub const IBV_ACCESS_LOCAL_WRITE: Self = Self(1 << 0);
60-
pub const IBV_ACCESS_REMOTE_WRITE: Self = Self(1 << 1);
61-
pub const IBV_ACCESS_REMOTE_READ: Self = Self(1 << 2);
62-
pub const IBV_ACCESS_REMOTE_ATOMIC: Self = Self(1 << 3);
63-
pub const IBV_ACCESS_MW_BIND: Self = Self(1 << 4);
64-
pub const IBV_ACCESS_ZERO_BASED: Self = Self(1 << 5);
65-
pub const IBV_ACCESS_ON_DEMAND: Self = Self(1 << 6);
66-
pub const IBV_ACCESS_HUGETLB: Self = Self(1 << 7);
67-
pub const IBV_ACCESS_RELAXED_ORDERING: Self = Self(1 << 8);
68-
pub const IBV_ACCESS_FLUSH_GLOBAL: Self = Self(1 << 9);
69-
pub const IBV_ACCESS_FLUSH_PERSISTENT: Self = Self(1 << 10);
70-
}
71-
72-
#[cfg(not(cargo))]
73-
impl std::ops::BitOr for ibv_access_flags {
74-
type Output = Self;
75-
fn bitor(self, rhs: Self) -> Self {
76-
Self(self.0 | rhs.0)
77-
}
78-
}
79-
8026
#[repr(C, packed(1))]
8127
#[derive(Debug, Default, Clone, Copy)]
8228
pub struct mlx5_wqe_ctrl_seg {

0 commit comments

Comments
 (0)