test(libc): keep the oversized allocation in the bad_alloc check observable to clang #28373

Merged
Jazeupoi merged 1 commit from upstream-pr/28373 into main 2026-12-04 07:37:30 +00:00
Jazeupoi commented 2026-11-30 10:17:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Jazeupoi on 2026-11-30T10:17:48Z.


What

guest_libstdcxx_dll_throws_badalloc fails on every run on macOS: std::bad_alloc from the runtime DLL was not caught by type. No exception is thrown at all. AllocateTooMany has internal linkage and its result was discarded with static_cast<void>, so clang drops the unused return value and then the allocation itself, which libc++ makes through __builtin_operator_new and therefore allows it to elide. libstdc++ throws from its PTRDIFF_MAX check before allocating, which is why the mode passes with GCC.

The check now stores the result in a volatile pointer, so the allocation stays and throws with either runtime.

Tested

macOS 27.0.1, Apple M4, x86_64 Release under Rosetta 2, Apple clang 21.0.0, on main 1b8f79a5b5 plus #26739, #27739 and #17425, which macOS needs to build (none touches this test; the file is unchanged up to 81ad4d40c5):

  • guest_libstdcxx_dll_throws_badalloc: 20/20. Without the change: fails on every run with the message above.
  • All seven guest_libstdcxx_dll_throws_* modes pass.
  • Windows and Linux: not run; the change only keeps the result alive, and libstdc++ throws before allocating there.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt and the licence notice of code adapted from upstream (see AGENTS.md)
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes (Claude Code)

Summary by CodeRabbit

  • Tests
    • Updated an internal test to retain the result of an allocation operation during execution. This is limited to test behavior and does not change any user-facing features, interfaces, or application functionality. No other user-visible changes are included in this update.
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5563292987 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/28373). Originally posted by [Jazeupoi](https://github.com/Jazeupoi) on 2026-11-30T10:17:48Z. --- ### What `guest_libstdcxx_dll_throws_badalloc` fails on every run on macOS: `std::bad_alloc from the runtime DLL was not caught by type`. No exception is thrown at all. `AllocateTooMany` has internal linkage and its result was discarded with `static_cast<void>`, so clang drops the unused return value and then the allocation itself, which libc++ makes through `__builtin_operator_new` and therefore allows it to elide. libstdc++ throws from its `PTRDIFF_MAX` check before allocating, which is why the mode passes with GCC. The check now stores the result in a `volatile` pointer, so the allocation stays and throws with either runtime. ### Tested macOS 27.0.1, Apple M4, x86_64 Release under Rosetta 2, Apple clang 21.0.0, on `main` `1b8f79a5b5` plus #26739, #27739 and #17425, which macOS needs to build (none touches this test; the file is unchanged up to `81ad4d40c5`): - `guest_libstdcxx_dll_throws_badalloc`: 20/20. Without the change: fails on every run with the message above. - All seven `guest_libstdcxx_dll_throws_*` modes pass. - Windows and Linux: not run; the change only keeps the result alive, and libstdc++ throws before allocating there. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt and the licence notice of code adapted from upstream (see AGENTS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's technical debt file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes (Claude Code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **Tests** * Updated an internal test to retain the result of an allocation operation during execution. This is limited to test behavior and does not change any user-facing features, interfaces, or application functionality. No other user-visible changes are included in this update. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
MarcZX10 commented 2026-11-30 10:20:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-30T10:20:13Z.

Review: APPROVED


Reviewed — looks good

Nothing in the reviewed change blocks merge; the allocation result is stored in a volatile pointer so its use remains observable.

What I ran

Reviewed head 447973899cea147cc8414cbc07018013cd676614. I read the prepared description, commit summary, manifest, diff, and the complete changed source file. No build or tests were run.

Results

Check Result Note
Diff and source review passed Changed file read in full
Tests not run No local execution

Findings

Blocking

None.

Non-blocking

None.

Not verified

The author reports macOS testing; I did not independently verify it. Windows and Linux behavior and test results were not verified. files.json was not available in the review folder, so the list of files excluded by rule was not verified. The manifest lists one changed file, and I read it in full.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6110357881 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/28373#pullrequestreview-6110357881). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-30T10:20:13Z. **Review:** APPROVED --- # Reviewed — looks good Nothing in the reviewed change blocks merge; the allocation result is stored in a volatile pointer so its use remains observable. ## What I ran Reviewed head `447973899cea147cc8414cbc07018013cd676614`. I read the prepared description, commit summary, manifest, diff, and the complete changed source file. No build or tests were run. ## Results | Check | Result | Note | |---|---|---| | Diff and source review | passed | Changed file read in full | | Tests | not run | No local execution | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified The author reports macOS testing; I did not independently verify it. Windows and Linux behavior and test results were not verified. `files.json` was not available in the review folder, so the list of files excluded by rule was not verified. The manifest lists one changed file, and I read it in full. ## To get this to a good state Nothing is required.
PrivacyOnion commented 2026-11-30 10:21:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-30T10:21:01Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 447973899c:

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_libstdcxx_dll_throws_tests built cleanly.
  • CTest (guest_libstdcxx_dll_throws_regex, guest_libstdcxx_dll_throws_base, guest_libstdcxx_dll_throws_rethrow, guest_libstdcxx_dll_throws_all, guest_libstdcxx_dll_throws_rethrown, guest_libstdcxx_dll_throws_filesystem, guest_libstdcxx_dll_throws_badalloc):
    1/7 Test #1645: guest_libstdcxx_dll_throws_regex ........   Passed    0.04 sec
    2/7 Test #1646: guest_libstdcxx_dll_throws_base .........   Passed    0.04 sec
    3/7 Test #1648: guest_libstdcxx_dll_throws_all ..........   Passed    0.02 sec
    4/7 Test #1650: guest_libstdcxx_dll_throws_filesystem ...   Passed    0.02 sec
    5/7 Test #1647: guest_libstdcxx_dll_throws_rethrow ......   Passed    0.02 sec
    6/7 Test #1649: guest_libstdcxx_dll_throws_rethrown .....   Passed    0.02 sec
    7/7 Test #1651: guest_libstdcxx_dll_throws_badalloc .....   Passed    0.02 sec
    100% tests passed, 0 tests failed out of 7
    
  • Code reading:
    • Verified core/libs/tests/GuestLibstdcxxDllThrows.cpp:27 global volatile pointer definition int* volatile allocated = nullptr; prevents optimization/elision of AllocateTooMany() result
    • Verified core/libs/tests/GuestLibstdcxxDllThrows.cpp:134 assignment in BadAllocReachesCatch preserves observable write across all compiler backends (clang/gcc) without introducing undefined behavior
    • Verified that volatile pointer assignment does not leak or cause issues since AllocateTooMany throws std::bad_alloc before returning, or if it were to return, the pointer is properly typed
    • Checked AGENTS.md compliance: no comments added, conventions pass, no unapproved headers or symbols introduced
    • Verified cross-platform consistency across Linux and macOS libc++/libstdc++ implementations

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6110368246 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/28373#pullrequestreview-6110368246). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-30T10:21:01Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `447973899c`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `guest_libstdcxx_dll_throws_tests` built cleanly. - **CTest** (`guest_libstdcxx_dll_throws_regex`, `guest_libstdcxx_dll_throws_base`, `guest_libstdcxx_dll_throws_rethrow`, `guest_libstdcxx_dll_throws_all`, `guest_libstdcxx_dll_throws_rethrown`, `guest_libstdcxx_dll_throws_filesystem`, `guest_libstdcxx_dll_throws_badalloc`): ``` 1/7 Test #1645: guest_libstdcxx_dll_throws_regex ........ Passed 0.04 sec 2/7 Test #1646: guest_libstdcxx_dll_throws_base ......... Passed 0.04 sec 3/7 Test #1648: guest_libstdcxx_dll_throws_all .......... Passed 0.02 sec 4/7 Test #1650: guest_libstdcxx_dll_throws_filesystem ... Passed 0.02 sec 5/7 Test #1647: guest_libstdcxx_dll_throws_rethrow ...... Passed 0.02 sec 6/7 Test #1649: guest_libstdcxx_dll_throws_rethrown ..... Passed 0.02 sec 7/7 Test #1651: guest_libstdcxx_dll_throws_badalloc ..... Passed 0.02 sec 100% tests passed, 0 tests failed out of 7 ``` - **Code reading**: - Verified core/libs/tests/GuestLibstdcxxDllThrows.cpp:27 global volatile pointer definition `int* volatile allocated = nullptr;` prevents optimization/elision of AllocateTooMany() result - Verified core/libs/tests/GuestLibstdcxxDllThrows.cpp:134 assignment in BadAllocReachesCatch preserves observable write across all compiler backends (clang/gcc) without introducing undefined behavior - Verified that volatile pointer assignment does not leak or cause issues since AllocateTooMany throws std::bad_alloc before returning, or if it were to return, the pointer is properly typed - Checked AGENTS.md compliance: no comments added, conventions pass, no unapproved headers or symbols introduced - Verified cross-platform consistency across Linux and macOS libc++/libstdc++ implementations Looks Good To Me
NobleBrains commented 2026-12-01 00:22:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by NobleBrains on 2026-12-01T00:22:04Z.

Review: APPROVED


Confirmed on macOS 15.

Setup: Apple M4, macOS 15.7.9, Apple clang 17.0.0 (clang-1700.6.3.2), x86_64 Release under Rosetta, BUILD_TESTING=ON. These are the OS and compiler generation of the macos-15 runner.
Tree: main 93d64f2d1e + the open macOS build fixes #27201, #27739, #27843, #17425, #27827, #27767 (main does not build on macOS without them, see #28168), + #22091, #28369, #28075, #28076, #28284, then #17878, #20161, #25134, #26806, #22932, #28373, #27828, #27950, #27582, #24311 merged one after another. All merged cleanly.

guest_libstdcxx_dll_throws_badalloc failures
same tree before this PR 3/3
with this PR at 447973899c 0/5

Full ctest -j 6 after all of them: 7047/7066 pass. Compared with the run before the second group of merges, no test fails that passed before.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6122949831 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/28373#pullrequestreview-6122949831). Originally posted by [NobleBrains](https://github.com/NobleBrains) on 2026-12-01T00:22:04Z. **Review:** APPROVED --- Confirmed on macOS 15. **Setup:** Apple M4, macOS 15.7.9, Apple clang 17.0.0 (clang-1700.6.3.2), x86_64 Release under Rosetta, `BUILD_TESTING=ON`. These are the OS and compiler generation of the `macos-15` runner. **Tree:** `main` `93d64f2d1e` + the open macOS build fixes #27201, #27739, #27843, #17425, #27827, #27767 (`main` does not build on macOS without them, see #28168), + #22091, #28369, #28075, #28076, #28284, then #17878, #20161, #25134, #26806, #22932, #28373, #27828, #27950, #27582, #24311 merged one after another. All merged cleanly. | `guest_libstdcxx_dll_throws_badalloc` | failures | |---|---| | same tree before this PR | 3/3 | | with this PR at `447973899c` | 0/5 | **Full `ctest -j 6`** after all of them: 7047/7066 pass. Compared with the run before the second group of merges, no test fails that passed before. AI-assisted: yes (Claude Code)
ligmaSec commented 2026-12-03 06:16:11 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T06:16:11Z.

Review: COMMENTED


Built the updated test against the repository runtime and ran all seven guest_libstdcxx_dll_throws CTest cases on Linux with GCC. All passed, including the typed std::bad_alloc catch. The new volatile pointer assignment makes the call result observable if allocation unexpectedly succeeds. The macOS compiler behavior was verified in the PR’s reported run.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6164599399 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/28373#pullrequestreview-6164599399). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T06:16:11Z. **Review:** COMMENTED --- Built the updated test against the repository runtime and ran all seven `guest_libstdcxx_dll_throws` CTest cases on Linux with GCC. All passed, including the typed `std::bad_alloc` catch. The new volatile pointer assignment makes the call result observable if allocation unexpectedly succeeds. The macOS compiler behavior was verified in the PR’s reported run. AI-assisted: yes.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!28373
No description provided.