test(libc): cover the standard exception classes and throw helpers #9773

Closed
DavidSamir wants to merge 1 commit from upstream-pr/9773 into main
DavidSamir commented 2026-10-22 14:11:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-22T14:11:58Z.


What

Line coverage of libc and libkernel over the CPU-side test suite (gcov, Windows) showed about 110 exports in exception/StandardExceptions.cpp that no test ran. They are the constructors, destructors, what and assignment of the standard exception classes, plus the throw helpers.

How:

  • New test tests/GuestStandardExceptionClasses.cpp, registered as guest_standard_exception_classes next to guest_bad_optional_access (it follows the same pattern):
    • exception, bad_alloc, bad_array_new_length, bad_cast, bad_typeid and bad_function_call:
      • the type record's name, and its base in the standard hierarchy (none for exception, bad_alloc for bad_array_new_length, otherwise exception);
      • the vtable's offset, type and what slot;
      • C1Ev and C2Ev install the vtable, and what() is non-empty and matches the vtable's what;
      • D1Ev and D2Ev run, and D0Ev deletes a malloced object.
    • logic_error, domain_error, invalid_argument, length_error, out_of_range and runtime_error:
      • the same type and vtable checks (base logic_error or exception);
      • what() returns the constructor's message, copied, so changing the caller's buffer afterwards doesn't affect it;
      • the copy constructors share the message;
      • assignment replaces it and returns the object, and self-assignment keeps it;
      • all three destructors run.
    • bad_weak_ptr (no exported constructor): its type, what and destructors.
    • Ten throw helpers throw: _Xbad_alloc, _Xrange_error, _Xlength_error, _Xinvalid_argument, _Throw_bad_weak_ptr, _Xbad_function_call, __throw_bad_variant_access, __cxa_bad_cast, __cxa_bad_typeid and __cxa_throw_bad_array_new_length.
  • what() text for the classes without a message is checked only for being non-empty; the console's exact strings are not pinned.

Tested

  • Windows 11 Pro 26200, WinLibs GCC 15.2.0, Release, no GPU involved: the new test passes, and so do the 21 exception and bad_* tests.
  • Negative control: with Assign keeping the old message, the test fails at the assignment check. Restored, it passes.
  • tools/check_conventions.py passes.

Overlap (tools/pr_overlap.py --branch plus git merge-tree):

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
  • 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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4968809797 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9773). Originally posted by [DavidSamir](https://github.com/DavidSamir) on 2026-10-22T14:11:58Z. --- ### What Line coverage of libc and libkernel over the CPU-side test suite (gcov, Windows) showed about 110 exports in `exception/StandardExceptions.cpp` that no test ran. They are the constructors, destructors, `what` and assignment of the standard exception classes, plus the throw helpers. How: - **New test `tests/GuestStandardExceptionClasses.cpp`, registered as `guest_standard_exception_classes`** next to `guest_bad_optional_access` (it follows the same pattern): - **`exception`, `bad_alloc`, `bad_array_new_length`, `bad_cast`, `bad_typeid` and `bad_function_call`:** - the type record's name, and its base in the standard hierarchy (none for `exception`, `bad_alloc` for `bad_array_new_length`, otherwise `exception`); - the vtable's offset, type and `what` slot; - `C1Ev` and `C2Ev` install the vtable, and `what()` is non-empty and matches the vtable's `what`; - `D1Ev` and `D2Ev` run, and `D0Ev` deletes a `malloc`ed object. - **`logic_error`, `domain_error`, `invalid_argument`, `length_error`, `out_of_range` and `runtime_error`:** - the same type and vtable checks (base `logic_error` or `exception`); - `what()` returns the constructor's message, copied, so changing the caller's buffer afterwards doesn't affect it; - the copy constructors share the message; - assignment replaces it and returns the object, and self-assignment keeps it; - all three destructors run. - **`bad_weak_ptr`** (no exported constructor): its type, `what` and destructors. - **Ten throw helpers** throw: `_Xbad_alloc`, `_Xrange_error`, `_Xlength_error`, `_Xinvalid_argument`, `_Throw_bad_weak_ptr`, `_Xbad_function_call`, `__throw_bad_variant_access`, `__cxa_bad_cast`, `__cxa_bad_typeid` and `__cxa_throw_bad_array_new_length`. - `what()` text for the classes without a message is checked only for being non-empty; the console's exact strings are not pinned. ### Tested - Windows 11 Pro 26200, WinLibs GCC 15.2.0, Release, no GPU involved: the new test passes, and so do the 21 exception and `bad_*` tests. - Negative control: with `Assign` keeping the old message, the test fails at the assignment check. Restored, it passes. - `tools/check_conventions.py` passes. Overlap (`tools/pr_overlap.py --branch` plus `git merge-tree`): - Nine PRs (#3965, #5021, #6044, #7081, #7201, #7447, #7715, #8150, #8965) touch `libc/CMakeLists.txt`; `git merge-tree` adds no conflict hunk with any of them. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/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
MarcZX10 commented 2026-10-22 14:38:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T14:38:29Z.

Review: APPROVED


The new test checks type records and base relationships, vtable address points, constructors/destructors (including deleting destructors), message ownership and assignment, and all ten throw helpers. I compared its expected object/vtable layout and behavior with StandardExceptions.cpp; the assertions match the implementation. The reported negative control for assignment adds useful red/green evidence.

Hosted register-context tests pass on Ubuntu and macOS Intel in Debug and Release; conventions, eligibility, relinker, ASan and write-watch checks also pass. Linux/Windows product jobs are skipped by policy. The current-main commits since the PR base do not touch StandardExceptions.cpp or this CMake section; merge-tree and diff-check are clean. I did not rerun CTest locally because there is no configured build and less than 1 GB free on disk.

#9775 also adds a separate CMake test registration in this block; the pairwise merge is clean and the registrations do not overlap semantically. No implementation duplicate was found.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5615981872 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9773#pullrequestreview-5615981872). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T14:38:29Z. **Review:** APPROVED --- The new test checks type records and base relationships, vtable address points, constructors/destructors (including deleting destructors), message ownership and assignment, and all ten throw helpers. I compared its expected object/vtable layout and behavior with `StandardExceptions.cpp`; the assertions match the implementation. The reported negative control for assignment adds useful red/green evidence. Hosted `register-context` tests pass on Ubuntu and macOS Intel in Debug and Release; conventions, eligibility, relinker, ASan and write-watch checks also pass. Linux/Windows product jobs are skipped by policy. The current-main commits since the PR base do not touch `StandardExceptions.cpp` or this CMake section; merge-tree and diff-check are clean. I did not rerun CTest locally because there is no configured build and less than 1 GB free on disk. #9775 also adds a separate CMake test registration in this block; the pairwise merge is clean and the registrations do not overlap semantically. No implementation duplicate was found.
MarcZX10 commented 2026-10-22 16:59:11 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T16:59:11Z.

Review: COMMENTED


The exact head f934c4b2c53aae56b3abebf933c32c27df08ba94 has a clean merge tree with current main (11f976b27c16ed91633f00039dba5dfd97dd7cc1); conventions and diff-check pass. The test covers the standard exception hierarchy, vtable slots, constructors/destructors, assignment, and throw helpers. The author reports Windows focused and exception-suite results; hosted register-context/relinker checks pass, while product Linux/Windows jobs are skipped. This branch is based on 8b3e39832a, 32 commits behind current main; please rebase and rerun guest_standard_exception_classes before merge. I did not rerun locally.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5617887257 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9773#pullrequestreview-5617887257). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T16:59:11Z. **Review:** COMMENTED --- The exact head `f934c4b2c53aae56b3abebf933c32c27df08ba94` has a clean merge tree with current main (`11f976b27c16ed91633f00039dba5dfd97dd7cc1`); conventions and diff-check pass. The test covers the standard exception hierarchy, vtable slots, constructors/destructors, assignment, and throw helpers. The author reports Windows focused and exception-suite results; hosted register-context/relinker checks pass, while product Linux/Windows jobs are skipped. This branch is based on `8b3e39832a`, 32 commits behind current main; please rebase and rerun `guest_standard_exception_classes` before merge. I did not rerun locally.
THEMANnt commented 2026-10-26 04:05:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by THEMANnt on 2026-10-26T04:05:47Z.

Review: APPROVED


Re-reviewed f934c4b2c53aae56b3abebf933c32c27df08ba94. Approve; the earlier validation blocker is resolved.

The missing native execution step is complete. Reviewed coverage exercises the standard exception type/vtable records, plain and message-object construction/destruction, message ownership/copies/assignment and the ten throw helpers. No actionable findings.

Validation: Compiled the complete exact GuestStandardExceptionClasses.cpp with the pinned exception runtime through its actual combined translation unit, src/exception/Exports.cpp, using project Windows unwind settings and section conversion. This includes Runtime, TypeInfo, StandardExceptions, Unwind and Personality source in their intended order. The complete test executable returns 0, including all throw/catch assertions.

Scope: Existing libc linkage supplies ancillary symbols; this is not a rebuild of every libc source or all exception tests. The earlier standalone StandardExceptions.cpp compilation failures were reviewer-harness errors caused by bypassing Exports.cpp, not defects introduced by this test. No application/game run.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5647255177 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9773#pullrequestreview-5647255177). Originally posted by [THEMANnt](https://github.com/THEMANnt) on 2026-10-26T04:05:47Z. **Review:** APPROVED --- Re-reviewed `f934c4b2c53aae56b3abebf933c32c27df08ba94`. Approve; the earlier validation blocker is resolved. The missing native execution step is complete. Reviewed coverage exercises the standard exception type/vtable records, plain and message-object construction/destruction, message ownership/copies/assignment and the ten throw helpers. No actionable findings. **Validation:** Compiled the complete exact GuestStandardExceptionClasses.cpp with the pinned exception runtime through its actual combined translation unit, src/exception/Exports.cpp, using project Windows unwind settings and section conversion. This includes Runtime, TypeInfo, StandardExceptions, Unwind and Personality source in their intended order. The complete test executable returns 0, including all throw/catch assertions. **Scope:** Existing libc linkage supplies ancillary symbols; this is not a rebuild of every libc source or all exception tests. The earlier standalone StandardExceptions.cpp compilation failures were reviewer-harness errors caused by bypassing Exports.cpp, not defects introduced by this test. No application/game run.

Pull request closed

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!9773
No description provided.