Skip to content

Commit 369b105

Browse files
committed
ci: add libc++ hardening, libstdc++ assertions, and UBSan
Two macOS jobs use libc++ debug hardening. The GCC 13 job uses _GLIBCXX_ASSERTIONS and UBSan. It deselects one at() test that reads a misaligned reference (#6309). Fix a test that bound a reference to a member of a packed struct. Assisted-by: ClaudeCode:claude-opus-5-5
1 parent a395471 commit 369b105

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ jobs:
6767
fuzz-replay: true
6868
- runs-on: macos-latest
6969
python-version: '3.14'
70-
cmake-args: -DCMAKE_CXX_STANDARD=14
70+
cmake-args: -DCMAKE_CXX_STANDARD=14 -DCMAKE_CXX_FLAGS=-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG
7171
- runs-on: windows-2022
7272
python-version: '3.9'
7373
cmake-args: -DPYBIND11_FINDPYTHON=OFF
@@ -399,7 +399,7 @@ jobs:
399399
cmake-args: -DCMAKE_CXX_STANDARD=17 -DPYBIND11_DISABLE_HANDLE_TYPE_NAME_DEFAULT_IMPLEMENTATION=ON
400400
- runs-on: macos-latest
401401
python-version: '3.14t'
402-
cmake-args: -DCMAKE_CXX_STANDARD=20
402+
cmake-args: -DCMAKE_CXX_STANDARD=20 -DCMAKE_CXX_FLAGS=-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG
403403
- runs-on: macos-latest
404404
python-version: '3.15'
405405
cmake-args: -DCMAKE_CXX_STANDARD=17
@@ -777,7 +777,9 @@ jobs:
777777
- gcc: 13
778778
std: 20
779779
container: "gcc:13"
780-
cxx_flags: "-Wall -Wextra -Wwrite-strings -Wunreachable-code -Wpointer-arith -Wredundant-decls"
780+
cxx_flags: "-Wall -Wextra -Wwrite-strings -Wunreachable-code -Wpointer-arith -Wredundant-decls -D_GLIBCXX_ASSERTIONS -fsanitize=undefined -fno-sanitize-recover=all"
781+
# at() returns a misaligned reference for this stride, see issue 6309
782+
pytest_addopts: "--deselect=test_numpy_array.py::test_at_stride_not_multiple_of_itemsize"
781783

782784
name: "🐍 3 • GCC ${{ matrix.gcc }} • C++${{ matrix.std }} • x64${{ matrix.cxx_flags && ' • cxx_flags' || '' }}"
783785
container: "${{ matrix.container }}"
@@ -822,6 +824,8 @@ jobs:
822824

823825
- name: Python tests
824826
run: cmake --build build --target pytest
827+
env:
828+
PYTEST_ADDOPTS: ${{ matrix.pytest_addopts }}
825829

826830
- name: C++ tests
827831
timeout-minutes: 3

‎tests/test_numpy_dtypes.cpp‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ PYBIND11_PACKED(struct NestedStruct {
5757
});
5858

5959
std::ostream &operator<<(std::ostream &os, const NestedStruct &v) {
60-
return os << "n:a=" << v.a << ";b=" << v.b;
60+
// Copy: binding a reference to a member of a packed struct can be misaligned.
61+
const SimpleStruct a = v.a;
62+
return os << "n:a=" << a << ";b=" << v.b;
6163
}
6264

6365
struct PartialStruct {

0 commit comments

Comments
 (0)