AGC tests: request memory spans outlive temporary Regions() vectors #7754

Closed
opened 2026-10-19 05:59:42 +00:00 by Amoenus · 0 comments
Amoenus commented 2026-10-19 05:59:42 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by Amoenus on 2026-10-19T05:59:42Z.


Observed on main

At 46f27623c28b237f6b7dab93862a318e4977cc19, ShaderMemory.cpp contains 20 assignments of a temporary ShaderMemory::Regions() result to a request's borrowed context.memory span. Representative sites are the out-of-range buffer-load fixture and the guarded-image store lambda.

ShaderMemory::Regions() returns std::vector<ShaderRecompiler::MemoryRegion> by value (declaration); GuestContext::memory is std::span<const MemoryRegion> (definition). The temporary vector is destroyed at the assignment's semicolon, before the following Recompile call can use or serialize the request. Keeping the ShaderMemory object alive does not retain the returned vector's region records.

This is the same test-lifetime pattern identified and corrected at one site in #757. That report describes a Linux failure during expected-error request serialization. The remaining sites above still exist after that PR merged; this is a report of those remaining instances, not a duplicate of its feature work.

Cppcheck 2.20 reports danglingTemporaryLifetime at the first two sites and several others in our current analysis; clang-tidy 23.1.3 also reports lifetime diagnostics in the same translation unit. The analysis used actual Windows build commands, with no parser/configuration errors or timeouts. Our analyzed integration is 689c0eae0eb7b12a3599b782ba87db5b53789ac6 on main 9f5d4bd929; the patterns and return/member types were separately verified against the exact current-main SHA above before filing.

Proposed correction

Active upstream fix: #7759 by @MarcZX10. It repairs these 20 sites and the additional image-table helper. Our independent exact-head validation records successful Windows/Linux builds and 20 fresh-process CPU passes (both affected fixtures, five repetitions per OS). Cppcheck and clang-tidy complete for both changed translation units with no remaining dangling-span diagnostics; unrelated advisories remain.

Our earlier one-file prototype is preserved as e3b870798, with its mainfeb adaptation. No duplicate upstream PR will be submitted.

Keep the returned region vector alive through every consumer of the request, following the existing repair in #757. For a single call:

const auto regions = memory.Regions();
request.context.memory = regions;
static_cast<void>(Recompile(request, *capture));

For reused requests and lambdas, keep ownership across subsequent capture/recompile calls or use a local request copy so an outer request does not retain a view after its owner dies. Each scope needs inspection; replacing the assignment mechanically is insufficient.

Validation limits

This is a test-correctness finding confirmed from the C++ ownership/types and analyzer diagnostics. No production API change, game unblock or newly reproduced title crash is claimed. ASan does not pass: unmodified main46f and our e3b prototype abort earlier in SPIRV-Tools / std::stable_sort with an allocator mismatch, separately reported as #7765. We did not suppress that check, and these sanitizer runs are not exact-head #7759 validation. Uninstrumented passes alone do not prove the former dangling accesses were safe. The allocator issue has since been fixed upstream by #7781; a full combined-fixture ASan rerun is pending here. Earlier pinned ASan failures remain historical results.

AI-assisted investigation/report: yes, Codex.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5918679603 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/7754). Originally posted by [Amoenus](https://github.com/Amoenus) on 2026-10-19T05:59:42Z. --- ### Observed on main At `46f27623c28b237f6b7dab93862a318e4977cc19`, `ShaderMemory.cpp` contains 20 assignments of a temporary `ShaderMemory::Regions()` result to a request's borrowed `context.memory` span. Representative sites are [the out-of-range buffer-load fixture](https://github.com/boykopovar/AnyPS5/blob/46f27623c28b237f6b7dab93862a318e4977cc19/core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp#L829) and [the guarded-image store lambda](https://github.com/boykopovar/AnyPS5/blob/46f27623c28b237f6b7dab93862a318e4977cc19/core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp#L1004). `ShaderMemory::Regions()` returns `std::vector<ShaderRecompiler::MemoryRegion>` by value ([declaration](https://github.com/boykopovar/AnyPS5/blob/46f27623c28b237f6b7dab93862a318e4977cc19/core/libs/prx/libSceAgcDriver/Execution/include/ShaderMemory.hpp#L72)); `GuestContext::memory` is `std::span<const MemoryRegion>` ([definition](https://github.com/boykopovar/AnyPS5/blob/46f27623c28b237f6b7dab93862a318e4977cc19/core/shader/recompiler/Recompiler.hpp#L238)). The temporary vector is destroyed at the assignment's semicolon, before the following `Recompile` call can use or serialize the request. Keeping the `ShaderMemory` object alive does not retain the returned vector's region records. ### Existing related evidence This is the same test-lifetime pattern [identified and corrected at one site in #757](https://github.com/boykopovar/AnyPS5/pull/757#issuecomment-6041643392). That report describes a Linux failure during expected-error request serialization. The remaining sites above still exist after that PR merged; this is a report of those remaining instances, not a duplicate of its feature work. Cppcheck 2.20 reports `danglingTemporaryLifetime` at the first two sites and several others in our current analysis; clang-tidy 23.1.3 also reports lifetime diagnostics in the same translation unit. The analysis used actual Windows build commands, with no parser/configuration errors or timeouts. Our analyzed integration is `689c0eae0eb7b12a3599b782ba87db5b53789ac6` on main `9f5d4bd929`; the patterns and return/member types were separately verified against the exact current-main SHA above before filing. ### Proposed correction **Active upstream fix: #7759 by @MarcZX10.** It repairs these 20 sites and the additional image-table helper. Our [independent exact-head validation](https://github.com/boykopovar/AnyPS5/pull/7759#issuecomment-6261730747) records successful Windows/Linux builds and **20 fresh-process CPU passes** (both affected fixtures, five repetitions per OS). Cppcheck and clang-tidy complete for both changed translation units with no remaining dangling-span diagnostics; unrelated advisories remain. Our earlier one-file prototype is preserved as [e3b870798](https://github.com/Amoenus/AnyPS5/commit/e3b8707988421618f3b33092af69cd00ca5e637d), with its [mainfeb adaptation](https://github.com/Amoenus/AnyPS5/commit/ebe0f11ea7dc745de9eefad8a40528a4e80a552d). No duplicate upstream PR will be submitted. Keep the returned region vector alive through every consumer of the request, following the existing repair in #757. For a single call: ```cpp const auto regions = memory.Regions(); request.context.memory = regions; static_cast<void>(Recompile(request, *capture)); ``` For reused requests and lambdas, keep ownership across subsequent capture/recompile calls or use a local request copy so an outer request does not retain a view after its owner dies. Each scope needs inspection; replacing the assignment mechanically is insufficient. ### Validation limits This is a test-correctness finding confirmed from the C++ ownership/types and analyzer diagnostics. No production API change, game unblock or newly reproduced title crash is claimed. ASan does **not** pass: unmodified main46f and our e3b prototype abort earlier in SPIRV-Tools / `std::stable_sort` with an allocator mismatch, separately reported as #7765. We did not suppress that check, and these sanitizer runs are not exact-head #7759 validation. Uninstrumented passes alone do not prove the former dangling accesses were safe. The allocator issue has since been fixed upstream by #7781; a full combined-fixture ASan rerun is pending here. Earlier pinned ASan failures remain historical results. AI-assisted investigation/report: yes, Codex.
Sign in to join this conversation.
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#7754
No description provided.