Enable stricter compiler warnings (-Wnon-virtual-dtor, -Woverloaded-virtual)#2327
Enable stricter compiler warnings (-Wnon-virtual-dtor, -Woverloaded-virtual)#2327maxwbuckley wants to merge 5 commits into
Conversation
…erloaded-virtual) Add `-Wshadow`, `-Wnon-virtual-dtor`, and `-Woverloaded-virtual` to the compiler warning flags for the library, tests, and benchmarks. These are enforced as errors via the existing `-Werror`. Third-party includes (rapids_logger, spdlog) are marked as SYSTEM to suppress upstream warnings. Fix all violations: - Rename variables/parameters that shadow outer-scope names, class members, type aliases, or inherited members across headers, sources, tests, and benchmarks - Add explicit virtual destructor to owning_wrapper - Replace C-style (void)0 cast with static_cast<void>(0) - Rename GTest INSTANTIATE_TEST_SUITE_P lambda params to avoid macro-internal shadow Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughSummary by CodeRabbit
WalkthroughRMM's build CMake files are updated to add -Wnon-virtual-dtor and -Woverloaded-virtual to C++ flags and to the CUDA host-compiler (-Xcompiler) warning lists for the main library, benchmarks, and tests, preserving existing warning and suppression settings. ChangesCompiler Warning Configuration
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
cpp/include/rmm/cuda_stream.hpp (1)
60-63:⚠️ Potential issue | 🟡 MinorUpdate Doxygen param name to match the signature.
After renaming to
stream_flags, the doc comment still uses@param flags, which makes API docs inconsistent.📝 Proposed fix
- * `@param` flags Stream creation flags. + * `@param` stream_flags Stream creation flags.As per coding guidelines, "
cpp/include/rmm/**/*.{h,hpp}: C++ public APIs must include Doxygen comments using /** ... */ format."Also applies to: 66-66
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@cpp/include/rmm/cuda_stream.hpp` around lines 60 - 63, The constructor Doxygen uses an out-of-date param tag (`@param` flags); update the comment for the CUDA stream constructor to use the correct parameter name (`@param` stream_flags) to match the function signature (constructor for class cuda_stream / function name cuda_stream::cuda_stream or similar) and ensure the comment uses the required /** ... */ Doxygen style; also apply the same fix to the other occurrence mentioned (the doc at the second occurrence).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@cpp/benchmarks/synchronization/synchronization.hpp`:
- Around line 69-71: Update the Doxygen `@param` for the cuda_event_timer
constructor to use the renamed parameter name "strm" instead of "stream"; locate
the declaration/definition of cuda_event_timer(benchmark::State& state, bool
flush_l2_cache, rmm::cuda_stream_view strm = rmm::cuda_stream_default) and
change the `@param` tag to `@param` strm (or rename the parameter back and make docs
consistent) so the documentation matches the actual argument name.
In `@cpp/include/rmm/exec_policy.hpp`:
- Around line 48-49: Update the Doxygen param names to match the constructor
signatures: change any "@param stream" to "@param strm" for the exec_policy
constructors (the explicit exec_policy(cuda_stream_view strm = ...,
device_async_resource_ref mr = ...) overload and the other constructor overload
referenced around the same area) so the public API docs match the actual
parameter name `strm` and avoid stale documentation.
---
Outside diff comments:
In `@cpp/include/rmm/cuda_stream.hpp`:
- Around line 60-63: The constructor Doxygen uses an out-of-date param tag
(`@param` flags); update the comment for the CUDA stream constructor to use the
correct parameter name (`@param` stream_flags) to match the function signature
(constructor for class cuda_stream / function name cuda_stream::cuda_stream or
similar) and ensure the comment uses the required /** ... */ Doxygen style; also
apply the same fix to the other occurrence mentioned (the doc at the second
occurrence).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 3def1fde-be46-4e74-b628-073ded4c98c6
📒 Files selected for processing (47)
cpp/CMakeLists.txtcpp/benchmarks/CMakeLists.txtcpp/benchmarks/random_allocations/random_allocations.cppcpp/benchmarks/replay/replay.cppcpp/benchmarks/synchronization/synchronization.cppcpp/benchmarks/synchronization/synchronization.hppcpp/benchmarks/utilities/log_parser.hppcpp/include/rmm/cuda_stream.hppcpp/include/rmm/detail/logging_assert.hppcpp/include/rmm/detail/runtime_capabilities.hppcpp/include/rmm/exec_policy.hppcpp/include/rmm/mr/arena_memory_resource.hppcpp/include/rmm/mr/detail/coalescing_free_list.hppcpp/include/rmm/mr/detail/free_list.hppcpp/include/rmm/mr/owning_wrapper.hppcpp/include/rmm/mr/pinned_host_memory_resource.hppcpp/include/rmm/mr/system_memory_resource.hppcpp/src/cuda_stream.cppcpp/src/exec_policy.cppcpp/src/logger.cppcpp/tests/CMakeLists.txtcpp/tests/cuda_stream_pool_tests.cppcpp/tests/device_buffer_tests.cucpp/tests/mr/aligned_mr_tests.cppcpp/tests/mr/arena_mr_tests.cppcpp/tests/mr/callback_mr_tests.cppcpp/tests/mr/host_mr_ref_tests.cppcpp/tests/mr/hwdecompress_tests.cppcpp/tests/mr/mr_ref_arena_tests.cppcpp/tests/mr/mr_ref_binning_tests.cppcpp/tests/mr/mr_ref_cuda_async_tests.cppcpp/tests/mr/mr_ref_cuda_tests.cppcpp/tests/mr/mr_ref_fixed_size_tests.cppcpp/tests/mr/mr_ref_managed_tests.cppcpp/tests/mr/mr_ref_pinned_pool_tests.cppcpp/tests/mr/mr_ref_pinned_tests.cppcpp/tests/mr/mr_ref_pool_tests.cppcpp/tests/mr/mr_ref_system_tests.cppcpp/tests/mr/mr_ref_test.hppcpp/tests/mr/mr_ref_test_basic.hppcpp/tests/mr/pool_mr_tests.cppcpp/tests/mr/prefetch_resource_adaptor_tests.cppcpp/tests/mr/resource_ref_conversion_tests.cppcpp/tests/mr/statistics_mr_tests.cppcpp/tests/mr/thrust_allocator_tests.cucpp/tests/mr/tracking_mr_tests.cppcpp/tests/prefetch_tests.cpp
Update @param tags in exec_policy.hpp (stream → strm), cuda_stream.hpp (flags → stream_flags), synchronization.hpp (stream → strm), and replay.cpp (args → simulated_size/events) so documentation matches the actual parameter names. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
All CodeRabbit review comments have been addressed in commit b9091a9:
|
| -Wall | ||
| -Werror | ||
| -Wextra | ||
| -Wshadow |
There was a problem hiding this comment.
Hi, thanks for the PR.
- Is there a specific environment where you’re observing these warnings?
- How did you select this set of warnings?
- Some seems fine to enable but I am unsure about -Wshadow. Can you justify this one in particular? We generally avoid the abbreviated names introduced here like
strmfor a stream orpfor a pointer in favor of full words.
RMM typically requires issues that motivate all pull requests so we have an archive of the library design decisions, could you file an issue containing that motivational information including what environments you observed these? I want to be sure RMM can meet requirements of the libraries depending on it, and I am not aware of any libraries requiring these flags that use RMM.
This PR has a large diff. I am currently refactoring a large part of the library and this will be hard to rebase into the staging branch. Once we settle on what changes we want to make, we can work on a PR based on the staging branch, but I may ask you to wait until some large open PRs land to avoid churn. Thanks!
There was a problem hiding this comment.
Also some companies (Google which I recently left) enforce strict compiler settings by default. So all of these issues make it harder to import RMM into third party.
There was a problem hiding this comment.
Thanks for the detailed feedback, Bradley!
Filed #2338 with the motivation. The short version: some organizations (Google, which I recently left) enforce strict compiler settings by default, so these warnings make it harder to import RMM into third-party projects using -Werror.
To answer your questions:
- I observed these warnings building with GCC 13 and Clang 18 using -Wall -Wextra -Wshadow -Wnon-virtual-dtor -Woverloaded-virtual -Werror.
- I selected these specific flags because they catch real bug classes (shadowing, missing virtual destructors, accidentally hidden overloads) and are commonly enforced in projects with strict warning policies.
- On -Wshadow specifically — I understand the preference for full names over abbreviations like
strm/p. Happy to rework those renames to use more descriptive alternatives that still avoid the shadowing (e.g.cuda_streaminstead ofstrm). Let me know what naming you'd prefer and I'll update.
Also happy to wait on the staging branch and rebase once your refactor lands — just let me know when it's a good time. Thanks again!
There was a problem hiding this comment.
Awesome. Yes, I think a lot of this will change on the staging branch (it's a near-total rewrite). The staging branch should stabilize in about a week or two. The last major change I need for that branch is #2325 and I'm currently working on splitting that PR up into smaller pieces and working out some design issues with CCCL upstream. I'll follow up on this thread once it's ready.
There was a problem hiding this comment.
I would expect this PR would cause some sort of breaking builds for downstream libraries. Can we switch this to draft mode, test it against downstream libraries first, apply the same set of compiler directive to them first if needed, then merge this one last?
There was a problem hiding this comment.
Following up from earlier: the major library changes are now complete, so I'm ready to start thinking about this PR again. We'll likely need to rebase or merge main -- maybe have an agent help you since the conflicts are large. You might also want to start fresh and apply these changes one flag at a time (maybe start with an easier one and we'll work up from there, -Wshadow is likely to be the largest one).
On
-Wshadowspecifically — I understand the preference for full names over abbreviations [...]. Let me know what naming you'd prefer and I'll update.
@maxwbuckley I think what I want to propose here is something like the Google C++ Style Guide:
sizeis a normal variable or parametersize_with a trailing underscore is used for (private) members
That should help with most cases as a starting point.
There was a problem hiding this comment.
I would expect this PR would cause some sort of breaking builds for downstream libraries.
@ttnghia Compiling RMM with additional compiler warnings will only enforce them for RMM, we won't propagate these flags to consumers of RMM:
target_compile_options(rmm PRIVATE "$<$<COMPILE_LANGUAGE:CXX>:${RMM_CXX_FLAGS}>"
"$<$<COMPILE_LANGUAGE:CUDA>:${RMM_CUDA_FLAGS}>")
Why
|
…r-warnings # Conflicts: # cpp/include/rmm/mr/owning_wrapper.hpp
Add `-Wnon-virtual-dtor` and `-Woverloaded-virtual` to the compiler warning flags for the library, tests, and benchmarks, enforced as errors via the existing `-Werror`. Some downstream projects (e.g. Google internal builds) enable these warnings as errors by default, so adding them here makes importing RMM into those builds easier. `-Wshadow` is intentionally not included in this PR; it will be a follow-up so we can settle on a Google-style naming convention (trailing-underscore members) for the shadow fixes separately. No source changes are required: both flags compile cleanly against the current codebase. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Thanks @bdice — I've rebased this against Current state:
@ttnghia — to address your earlier concern about downstream impact: as Bradley noted, |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
cpp/tests/CMakeLists.txt (1)
255-266: ⚡ Quick winApply
RMM_TESTS_CXX_FLAGSto the standalone shutdown test target.
PROCESS_IS_EXITING_SHUTDOWN_TESTbypassesConfigureTestInternal, so it currently misses the stricter warning set enabled in this PR for tests.Suggested patch
add_executable(PROCESS_IS_EXITING_SHUTDOWN_TEST process_is_exiting_shutdown_test.cpp) target_include_directories(PROCESS_IS_EXITING_SHUTDOWN_TEST PRIVATE "$<BUILD_INTERFACE:${RMM_SOURCE_DIR}>") target_link_libraries(PROCESS_IS_EXITING_SHUTDOWN_TEST PRIVATE rmm $<TARGET_NAME_IF_EXISTS:conda_env>) +target_compile_options( + PROCESS_IS_EXITING_SHUTDOWN_TEST + PRIVATE "$<$<COMPILE_LANGUAGE:CXX>:${RMM_TESTS_CXX_FLAGS}>" + "$<$<COMPILE_LANGUAGE:CUDA>:${RMM_TESTS_CUDA_FLAGS}>") set_target_properties( PROCESS_IS_EXITING_SHUTDOWN_TEST PROPERTIES POSITION_INDEPENDENT_CODE ON RUNTIME_OUTPUT_DIRECTORY "$<BUILD_INTERFACE:${RMM_BINARY_DIR}/gtests>" INSTALL_RPATH "\$ORIGIN/../../../lib" CXX_STANDARD 20 CXX_STANDARD_REQUIRED ON)🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@cpp/tests/CMakeLists.txt` around lines 255 - 266, The standalone test target PROCESS_IS_EXITING_SHUTDOWN_TEST bypasses ConfigureTestInternal and therefore doesn't inherit the stricter warning/compile flags; add the RMM_TESTS_CXX_FLAGS to that target (e.g., call target_compile_options(PROCESS_IS_EXITING_SHUTDOWN_TEST PRIVATE ${RMM_TESTS_CXX_FLAGS}) or equivalent) after the target is created/linked so the test uses the same C++ warning and compile options as other tests.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@cpp/tests/CMakeLists.txt`:
- Around line 255-266: The standalone test target
PROCESS_IS_EXITING_SHUTDOWN_TEST bypasses ConfigureTestInternal and therefore
doesn't inherit the stricter warning/compile flags; add the RMM_TESTS_CXX_FLAGS
to that target (e.g., call
target_compile_options(PROCESS_IS_EXITING_SHUTDOWN_TEST PRIVATE
${RMM_TESTS_CXX_FLAGS}) or equivalent) after the target is created/linked so the
test uses the same C++ warning and compile options as other tests.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 496006d0-ad55-490b-8b77-49a16d7e7942
📒 Files selected for processing (3)
cpp/CMakeLists.txtcpp/benchmarks/CMakeLists.txtcpp/tests/CMakeLists.txt
bdice
left a comment
There was a problem hiding this comment.
I see your testing plan mentioned some existing segfaults. Can you file an issue with more information on how to reproduce?
|
/ok to test b444650 |
|
Followed up on the segfault question — turns out it's environmental on my WSL2 dev box, not an RMM bug, so I don't think it warrants an upstream issue. Quick writeup in case it saves the next person the same dig: Symptom. Stack (
Root cause. Two
Workaround: All 5 tests pass; the Fabric handles test skips. Permanent fix on my side: Implication for this PR. Confirmed the crashing files ( I'll skip filing an upstream issue unless you'd prefer one for searchability — happy to do that if so. |
Summary
Add
-Wnon-virtual-dtorand-Woverloaded-virtualto the compiler warning flags for the library, tests, and benchmarks, enforced as errors via the existing-Werror. Both flags compile cleanly against the current codebase — this PR is CMake-only, no source changes required.Why
Some downstream organizations (e.g. Google's internal build) enforce strict warning policies by default, which makes importing RMM into those builds harder. More importantly, the codebase as it stands today is already clean against these two flags; enabling them in CI locks that in as a regression gate, so future contributors can't accidentally introduce:
-Wnon-virtual-dtor) — a well-known source of undefined-behavior when deleting via a base pointer.-Woverloaded-virtual) — typically a silent bug where the override never gets called.CI will now catch either of these at the warning-as-error stage rather than at runtime.
Scope note
This PR originally also added
-Wshadow, but that flag triggers a much larger set of source-level renames and was split off into a separate PR so the naming convention can be reviewed independently.Follow-up:
-Wshadowis being addressed in #2417 using the Google C++ style convention (sizefor params/locals, trailing-underscoresize_for private members) suggested by @bdice. With #2417 landed, RMM will enforce all three stricter warning flags discussed in this thread.Test plan
-Werrorand the two new flags — zero warnings.ctestpasses (failures observed locally are pre-existing runtime SEGVs inCUDA_ASYNC_MR_SHARED_CUDART_TEST, unrelated to compile-flag changes).cmake-formatandcmake-lintclean.🤖 Generated with Claude Code