-
Notifications
You must be signed in to change notification settings - Fork 497
Clang21 build fix #10998
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Clang21 build fix #10998
Conversation
WalkthroughReplaces deprecated C++ Changes
Sequence Diagram(s)Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/ucs/datastruct/static_bitmap.h(2 hunks)test/apps/iodemo/io_demo.cc(3 hunks)
🔇 Additional comments (4)
test/apps/iodemo/io_demo.cc (2)
23-23: LGTM!The
<random>header is correctly added to supportstd::random_deviceandstd::mt19937used in the C++17+ code path.
3003-3013: Good modernization for C++17 compatibility.The conditional compilation correctly addresses the removal of
std::random_shufflein C++17. The implementation properly usesstd::shufflewith a proper random number generator for C++17+ while maintaining backward compatibility.src/ucs/datastruct/static_bitmap.h (2)
229-237: LGTM!Zero-initializing
_r_##_uidproperly addresses Clang 21's-Wdefault-const-init-var-unsafewarning. The variable is immediately populated by the bitmap operation, so this initialization has no runtime impact beyond satisfying the compiler check.
254-265: LGTM!Zero-initializing
_r_##_uidproperly addresses Clang 21's-Wdefault-const-init-var-unsafewarning. The variable is immediately populated by the bitmap binary operation, so this initialization has no runtime impact beyond satisfying the compiler check.
5d2109e to
a950e7a
Compare
6f11c87 to
9ac4c2c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
config/m4/compiler.m4(1 hunks)test/apps/iodemo/io_demo.cc(2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- test/apps/iodemo/io_demo.cc
| # Initialize CFLAGS | ||
| # | ||
| BASE_CFLAGS="-g -Wall -Werror" | ||
| BASE_CFLAGS="-g -Wall" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider a more targeted approach than removing -Werror entirely.
Removing -Werror from BASE_CFLAGS disables error-on-warning for the entire build, which reduces code quality enforcement. This means all warnings—not just the Clang 21 -Wdefault-const-init-var-unsafe issue—will be silently ignored, potentially masking future bugs.
Recommended alternatives:
-
Selectively disable the problematic warning (preferred):
-BASE_CFLAGS="-g -Wall" +BASE_CFLAGS="-g -Wall -Werror"
Then add after line 302:
# # Disable Clang 21 default-const-init-var-unsafe warning # ADD_COMPILER_FLAG_IF_SUPPORTED([-Wno-error=default-const-init-var-unsafe], [-Wno-error=default-const-init-var-unsafe], [AC_LANG_SOURCE([[int main(int argc, char** argv){return 0;}]])], [], [])
-
Version-specific handling (if the warning only affects Clang 21+):
Detect the compiler version and conditionally apply flags only when needed.
The file already provides ADD_COMPILER_FLAG_IF_SUPPORTED and CHECK_COMPILER_FLAG macros (lines 252, 226) specifically for this purpose. Using -Wno-error=default-const-init-var-unsafe would downgrade only this specific warning to non-fatal while preserving -Werror for all other warnings.
🤖 Prompt for AI Agents
In config/m4/compiler.m4 around line 13, do not remove -Werror from BASE_CFLAGS;
instead retain it and add a targeted suppression for the Clang 21 warning after
line 302 by calling ADD_COMPILER_FLAG_IF_SUPPORTED to add
-Wno-error=default-const-init-var-unsafe when supported (use the same
AC_LANG_SOURCE probe pattern used elsewhere). Alternatively, if you prefer
compiler-aware handling, detect Clang and its version and conditionally append
that -Wno-error flag only for affected Clang versions so -Werror remains active
for all other warnings.
First caught on Gentoo LLVM with Clang 21.1.5 and LLVM 21.1.5
Build with fail with the following error message
core/ucp_context.c:2673:47: error: default initialization of an object of type
'typeof (*tl_bitmap_super)' (aka 'const ucp_tl_bitmap_t') leaves the object uninitialized
[-Werror,-Wdefault-const-init-var-unsafe]
/var/tmp/portage/sys-cluster/ucx-1.19.0/work/ucx-1.19.0/src/ucs/datastruct/static_bitmap.h:250:5: note:
expanded from macro 'UCS_STATIC_BITMAP_NOT'
250 | UCS_STATIC_BITMAP_UNARY_OP(_bitmap, not, UCS_PP_UNIQUE_ID)
| ^
/var/tmp/portage/sys-cluster/ucx-1.19.0/work/ucx-1.19.0/src/ucs/datastruct/static_bitmap.h:239:5: note:
expanded from macro 'UCS_STATIC_BITMAP_UNARY_OP'
239 | _UCS_STATIC_BITMAP_UNARY_OP(_bitmap, _op_name, _uid)
| ^
/var/tmp/portage/sys-cluster/ucx-1.19.0/work/ucx-1.19.0/src/ucs/datastruct/static_bitmap.h:232:29: note:
expanded from macro '_UCS_STATIC_BITMAP_UNARY_OP'
232 | ucs_typeof(_bitmap) _r_##_uid; \
| ^
<scratch space>:54:1: note: expanded from here
54 | _r_0
| ^
core/ucp_context.c:2672:25: error: default initialization of an object of type
'typeof (*tl_bitmap)' (aka 'const ucp_tl_bitmap_t') leaves the object uninitialized
[-Werror,-Wdefault-const-init-var-unsafe]
2672 | ucp_tl_bitmap_t b = UCS_STATIC_BITMAP_AND(*tl_bitmap,
| ^
This is cause due to Clang enabling default-const-init-var-unsafe by default,
and -Werror makes it treat as an warning. This is better fixed by upstream
developer so this commit mostly a RFC from upstream.
Signed-off-by: Brahmajit Das <[email protected]>
random_shuffle was deprecated in C++14 and completely removed in C++17. With newer compilers like Clang 21, the build fails. This commit should preserve older behavior and use std::shuffle when available. Signed-off-by: Brahmajit Das <[email protected]>
9ac4c2c to
2c07e61
Compare
| # Initialize CFLAGS | ||
| # | ||
| BASE_CFLAGS="-g -Wall -Werror" | ||
| BASE_CFLAGS="-g -Wall" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing -Werror seems too broad.
How many errors do we see with default-const-init-var-unsafe? Maybe we can change the code on those places to make it silent?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So that was the idea before, but thought -Werror should be enabled in dev builds only. You can see what I initially did to suppress the build failure with clang here:
https://github.com/openucx/ucx/compare/6f11c87850dd7b401e975e56e915a6a771478351
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we can fix the code to avoid the warning - this is preferred.
if not possible to fix the code - we can disable a specific warning, but IMO we should keep -Werror
What?
Currently UCX is failing to build with newer compiler (for example Clang 21). This PR fixes that.
Why?
This is cause due to Clang enabling default-const-init-var-unsafe by default,
and
-Werrormakes it treat as an warning. This is better fixed by upstreamdeveloper so
-Werrorcommit mostly a RFC from upstream.Also std::random_shuffle has been removed since C++17 (deprecated in C++14). PR would make use of recommended std::shuffle.
How?
Not needed in this case I guess :)
Summary by CodeRabbit
Refactor
Chores
✏️ Tip: You can customize this high-level summary in your review settings.