fix(libc): implement RTTI cast result callbacks #10416
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10416"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T22:52:34Z.
What
Implement the Itanium RTTI
__do_upcastresult and__do_dyncastcallbacks. Traverse guest class metadata to preserve subobject offsets, public and private paths, virtual bases, and repeated base ambiguity. Extend the guest dynamic cast fixture to cover those paths. The separate__do_find_public_srccallback is not changed in this pull request.Tested
Linux, GCC 12.2: compiled
Runtime.cpp,TypeInfo.cppandGuestDynamicCast.cppwith-Wall -Wextra -Werror; linked and ran the focused fixture with AddressSanitizer and UndefinedBehaviorSanitizer. The fixture passed for public and private upcasts, repeated-base ambiguity, virtual-base offsets, downcasts, crosscasts and rejected private paths. A full CMake configure was attempted but could not proceed because the SDL2 submodule is absent and the environment lacks XRandR support.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-24T05:40:00Z.
Review: COMMENTED
Checked against main
7c2400d29band GCC libsupc++ releases/gcc-14.2.0 (04696df096,vmi_class_type_info.cc__do_upcast/__do_dyncast,dyncast.cc):Runtime.cppusesClassTypeInfo::__contained_virtual_mask,__contained_public_mask,__contained_ambig,__not_containedand__contained_public. On libc++abi hosts, main'sspecifics/itanium/CxxAbi.hpponly declaresenum __sub_kind { __unknown = 0 };, so I'd expect the full macOS build to fail to compile. I couldn't build it here, and CI's macOS jobs are relinker-only, so it wouldn't show up there. Adding the enumerators toCxxAbi.hpp, or using integer constants as #10411 does, would avoid it.DynamicCastTypeInfo,sourceVisitorassignstoSource = baseLocation.path;(L353), so in a virtual diamond the last-visited path wins. Example:W : private D,D : public B1, public B2,B1 : public virtual S,B2 : private virtual S, casting W'sS*toD*. B2's private path overwrites B1's public one, D is not treated as a downcast, and the result is null, while libsupc++ (via__find_public_src) and main's own__dynamic_cast_nid_postfixboth return D. ORing the paths fixes it.W : public X, private Y, public S,X : public D,Y : public D, casting from S to D returns X's D, while libsupc++'s vmi__do_dyncastvisits the private copy (non-diamond repeat) and returns NULL as ambiguous. Main'sBases()has the same public-only counting, so this isn't new, butUpcastTypeInfoResulthere already treats any second identity as ambiguous. Could the cross-cast check do the same?__do_upcastskips private bases whensrc_detailslacks__non_diamond_repeat_mask, soPrivateTypegives false/__unknownthere rather than true/__contained_private. It's harmless throughcontained_public_p, but the test currently pins the non-libsupc++ value.CallDynamicCastalways passessrc2dst = 0, which claims a public base at offset 0. One or two diamond fixtures, for example the two above, would cover the risky parts.TypeInfo.cppandGuestDynamicCast.cpp.Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-02T04:57:25Z.
Review: COMMENTED
Reviewed — regression claim confirmed by reading, not yet fixed
The early multiple-subobject return runs before the downcast branch, so the reviewer's regression is present at this head; the requested fix and test are not in the diff.
What I ran
Results
Findings
candidates.size() > 1early return in DynamicCastTypeInfo returns ambiguous before the downcast branch, so a downcast to Mid through A's subobject returns null.candidates.size() > 1.downcasts.size() == 1) is at Runtime.cpp:393-398, after it.candidates.size() == 1) and a test for the downcast shape: not present. The test file has no type named Mid (grep).Sources
github.com/boykopovar/AnyPS5@0a490de29d/core/libs/prx/libc/src/exception/Runtime.cpp (L382-L398)github.com/boykopovar/AnyPS5@0a490de29d/core/libs/prx/libc/src/exception/Runtime.cpp (L403-L405)Not verified