Skip to content

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

Open
Thimo188 wants to merge 1 commit into
mainfrom
upstream-pr/28373
Open

Thimo188 wants to merge 1 commit into
mainfrom
upstream-pr/28373

Conversation

@Thimo188

@Thimo188 Thimo188 commented Dec 3, 2026 •

Copy link
Copy Markdown
Owner

Imported from boykopovar/AnyPS5#28373, originally opened by Jazeupoi.

Source commit: 447973899cea147cc8414cbc07018013cd676614. The import branch preserves this fetched upstream PR snapshot. The description and validation below are copied from upstream; no new code changes or test runs were made for this import. Original reviews, discussions, and attachments remain at the linked upstream PR.


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 boykopovar#26739, boykopovar#27739 and boykopovar#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 allocation-failure test to retain the result of its allocation attempt while checking for the expected exception. No end-user behavior changes are included in this update.

@coderabbitai

coderabbitai Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Changes: Bad allocation test

Layer / File(s) Summary
Retain allocation result
core/libs/tests/GuestLibstdcxxDllThrows.cpp
The test adds a namespace-scope volatile pointer and assigns the allocation result to it in BadAllocReachesCatch. The exception handling is unchanged.

Suggested reviewers: claude

Change: Other

Merge Risk: Minimal · up to 44797

This change only makes a test more robust on macOS by keeping an oversized allocation from being optimized away. It does not touch production behavior and is low risk to merge.

Security architecture risk: Minimal · up to 44797

The GuestLibstdcxxDllThrows test now makes the allocation result observable so the compiler cannot discard the allocation attempt. The exception and cleanup assertions are unchanged, and no production behavior changes.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Usage-based review receipt

  • Mode: Continue automatically
  • Reviewed files: 1
  • Waived: $0.25 (charged $0.00)
  • View usage details

Note

This review exceeded your plan’s limits and used usage-based reviews—free during trial, billed after paid activation unless disabled. Manage usage-based reviews.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b4a3cf7b-a2b3-4dba-90e2-ae52613a9788
Commits

Reviewing files that changed from the base of the PR and between 4131f51 and 4479738.

Files selected for processing: 1

  • core/libs/tests/GuestLibstdcxxDllThrows.cpp

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.

2 participants