Skip to content

Suppress -Wmaybe-uninitialized for onnxruntime_pybind11_state under pybind11 3.0#28251

Open
Rishi-Dave wants to merge 2 commits intomicrosoft:mainfrom
Rishi-Dave:rishidave/fix/pybind11-v3-werror-uninitialized
Open

Suppress -Wmaybe-uninitialized for onnxruntime_pybind11_state under pybind11 3.0#28251
Rishi-Dave wants to merge 2 commits intomicrosoft:mainfrom
Rishi-Dave:rishidave/fix/pybind11-v3-werror-uninitialized

Conversation

@Rishi-Dave
Copy link
Copy Markdown
Contributor

Summary

  • Probes -Wmaybe-uninitialized via check_cxx_compiler_flag and applies -Wno-maybe-uninitialized only to the onnxruntime_pybind11_state target when the compiler accepts it.
  • Fixes the GCC build break introduced when ORT is compiled against pybind11 3.0, currently blocking Fedora's pybind11 3.0 package update.

Motivation

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 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: add check_cxx_compiler_flag(-Wno-maybe-uninitialized HAS_NO_MAYBE_UNINITIALIZED) next to the existing HAS_CAST_FUNCTION_TYPE probe.
  • cmake/onnxruntime_python.cmake: when HAS_NO_MAYBE_UNINITIALIZED is set, append -Wno-maybe-uninitialized to the onnxruntime_pybind11_state target's private compile options. Mirrors the established HAS_CAST_FUNCTION_TYPE pattern 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 -a clean on the diff.
  • CI: confirm Linux GCC builds remain green.
  • Downstream verification: Fedora packagers can rebuild ORT against system pybind11 3.0 without -Wmaybe-uninitialized errors (per issue reporter).

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
Copy link
Copy Markdown
Contributor

@tianleiwu tianleiwu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Comment thread cmake/CMakeLists.txt Outdated
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)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@Rishi-Dave
Copy link
Copy Markdown
Contributor Author

Thanks for the catch — pushed acae123 which drops the redundant -Wno-maybe-uninitialized probe and reuses the existing HAS_MAYBE_UNINITIALIZED from CMakeLists.txt:651 to gate the suppression in onnxruntime_python.cmake, mirroring the HAS_CAST_FUNCTION_TYPE pattern. Net diff is now a single condition in onnxruntime_python.cmake — no new probe added.

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.

[Build] Pybind11 3.0 support

2 participants