Skip to content

Conversation

@r-barnes
Copy link

@r-barnes r-barnes commented Dec 13, 2025

When compiling code that includes the header infiniband/verbs.h with CUDA using C++20 we observe:

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 use of enums seems to be a pre-C++11 way of generating compile-time constants. This PR uses explicit casts to suppress the compile-time warning.

This code, is of course C, but the enum-enum conversion issues leak out into C++ because they're in a header. There are a few options:

  • Use explicit casts to suppress the warning (what I've done here)
  • Change the code so it uses constants - the enums don't seem semantically meaningful here.
  • Upgrade to the C23 standard to gain access to constexpr (heavyweight solution).
  • Suppress the relevant compiler flags in this header using #pragma clang diagnostic push and #pragma clang diagnostic pop (it's more complicated than this, but folly has a macro that could be copied to cover all scenarios)

The current code's use of enums seems as though it could cause increasing compilation issues over time, so fixing it seems like a good idea.

Let me know what you'd like to do - I'm happy to help.

@r-barnes r-barnes changed the title Convert enums to constants for compatibility with C++20 Fix enum-enum math for compatibility with C++20 Dec 13, 2025
r-barnes added a commit to r-barnes/monarch that referenced this pull request Dec 15, 2025
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
@jgunthorpe
Copy link
Member

I think since these are intended to be used by an application that will | them together the only answer is to change them to #define's. Otherwise the app will hit these warnings too.

@jgunthorpe
Copy link
Member

And if we are going to do this we should do it for all the enum's being used for defining bit fields.

meta-codesync bot pushed a commit to meta-pytorch/monarch that referenced this pull request Dec 16, 2025
…sts (#2147)

Summary:
Pull Request resolved: #2147

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

fbshipit-source-id: 9a0164b34e02e0f06781b5cd64a0b6163a71663c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants