Suppress -Wmaybe-uninitialized for onnxruntime_pybind11_state under pybind11 3.0#28251
Suppress -Wmaybe-uninitialized for onnxruntime_pybind11_state under pybind11 3.0#28251Rishi-Dave wants to merge 2 commits intomicrosoft:mainfrom
Conversation
pybind11 3.0 rewrote def_readwrite to use a property_cpp_function_classic template that generates a lambda capturing a member pointer by value. GCC's -Wmaybe-uninitialized flow analysis flags that lambda, which breaks builds against the system-provided pybind11 3.0 (notably the Fedora packaging update). The warning originates inside pybind11's own headers, so suppressing it locally on the onnxruntime_pybind11_state target is the minimal correct fix. The flag is probed via check_cxx_compiler_flag (matching the existing HAS_CAST_FUNCTION_TYPE pattern) so it is only applied when the compiler accepts it. Fixes microsoft#25681
tianleiwu
left a comment
There was a problem hiding this comment.
Review Summary
Clean, well-motivated fix for the pybind11 3.0 GCC build break. The target-scoped suppression with clear comments and issue reference follows established patterns nicely.
One suggestion to simplify: cmake/CMakeLists.txt already probes for -Wmaybe-uninitialized (positive form) at line 651 and sets HAS_MAYBE_UNINITIALIZED. Since GCC always pairs -W<x> and -Wno-<x> flags, the new HAS_NO_MAYBE_UNINITIALIZED probe is redundant. Using the existing variable would reduce this to a single-file change and match the HAS_CAST_FUNCTION_TYPE pattern (probe positive form, apply negative form).
| check_cxx_compiler_flag(-Warray-bounds HAS_ARRAY_BOUNDS) | ||
| check_cxx_compiler_flag(-Wbitwise-instead-of-logical HAS_BITWISE_INSTEAD_OF_LOGICAL) | ||
| check_cxx_compiler_flag(-Wcast-function-type HAS_CAST_FUNCTION_TYPE) | ||
| check_cxx_compiler_flag(-Wno-maybe-uninitialized HAS_NO_MAYBE_UNINITIALIZED) |
There was a problem hiding this comment.
Suggestion: This probe is redundant — line 651 of this file already does:
check_cxx_compiler_flag(-Wmaybe-uninitialized HAS_MAYBE_UNINITIALIZED)GCC always pairs -W<x> and -Wno-<x>, so if HAS_MAYBE_UNINITIALIZED is true, -Wno-maybe-uninitialized is guaranteed to be accepted. You can drop this new line entirely and use if(HAS_MAYBE_UNINITIALIZED) in onnxruntime_python.cmake instead.
This also fixes the ordering issue — the new line is currently placed among the 'c' flags, but alphabetically -Wno-maybe-uninitialized (or its 'm' base) belongs later in the list.
Matches the existing pattern where HAS_CAST_FUNCTION_TYPE probes the positive form and the target applies the negative -Wno-cast-function-type.
The dedicated `-Wno-maybe-uninitialized` probe added at CMakeLists.txt:637 is redundant: the positive-form probe `HAS_MAYBE_UNINITIALIZED` already exists at line 651, and GCC always supports `-W<x>` and `-Wno-<x>` as a pair. Remove the new probe and gate the pybind11 suppression on the existing variable, mirroring the HAS_CAST_FUNCTION_TYPE pattern. Per reviewer feedback on PR microsoft#28251.
|
Thanks for the catch — pushed |
Summary
-Wmaybe-uninitializedviacheck_cxx_compiler_flagand applies-Wno-maybe-uninitializedonly to theonnxruntime_pybind11_statetarget when the compiler accepts it.Motivation
pybind11 3.0 rewrote
def_readwriteto use aproperty_cpp_function_classictemplate that generates a lambda capturing a member pointer by value. GCC's-Wmaybe-uninitializedflow analysis flags that lambda inside pybind11's own headers, so any consumer compiling ORT's Python bindings against system pybind11 3.0 fails the build. This is a header-side false positive — there is no real uninitialized read in ORT code or in pybind11.Fixes #25681
Changes
cmake/CMakeLists.txt: addcheck_cxx_compiler_flag(-Wno-maybe-uninitialized HAS_NO_MAYBE_UNINITIALIZED)next to the existingHAS_CAST_FUNCTION_TYPEprobe.cmake/onnxruntime_python.cmake: whenHAS_NO_MAYBE_UNINITIALIZEDis set, append-Wno-maybe-uninitializedto theonnxruntime_pybind11_statetarget's private compile options. Mirrors the establishedHAS_CAST_FUNCTION_TYPEpattern in the same file.The suppression is target-scoped (only the Python binding shared library), compiler-scoped (only when the flag is accepted — effectively GCC), and warning-scoped (only the flow-sensitive
-Wmaybe-uninitialized, not the strict-Wuninitialized).Test Plan
lintrunner -aclean on the diff.-Wmaybe-uninitializederrors (per issue reporter).