[Enh] Add verifier for RecastIterOp to reject unsound pointer recasts#598
Open
Peter9606 wants to merge 1 commit into
Open
[Enh] Add verifier for RecastIterOp to reject unsound pointer recasts#598Peter9606 wants to merge 1 commit into
Peter9606 wants to merge 1 commit into
Conversation
fly.recast_iter reinterprets a pointer's element type, but its result type is supplied by the caller, so an invalid result pointer (e.g. one that silently changes the address space) previously passed through to lowering and could produce undefined runtime behavior. Add a verifier enforcing that the result pointer: - keeps the same address space as the source (a reinterpret cannot move shared memory into global, etc.); - only narrows the alignment guarantee (result alignment must divide the source alignment) -- narrowing is sound, widening is not; - keeps the same swizzle. Add FileCheck negative tests covering each rejected case. Assisted-by: Cursor (Opus4.8) Signed-off-by: Fujun Han <fujun.han@iluvatar.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
fly.recast_iter reinterprets a pointer's element type, but its result type is supplied by the caller. Previously the result pointer was not validated at all — e.g. recasting a shared-memory pointer into global would silently flow through to lowering and cause undefined runtime behavior.
This PR adds a verifier for RecastIterOp that requires the result pointer to:
keep the same address space as the source (a reinterpret cannot move memory across address spaces);
only narrow the alignment guarantee (result alignment must divide source alignment) — narrowing is sound, widening is not;
keep the same swizzle.
Narrowing is intentionally allowed: existing kernels (e.g. preshuffle_gemm_v2) recast the 1024B-aligned dynamic shared base down to a 512B-aligned typed pointer.
Test
Adds tests/mlir/Conversion/recast_iter_invalid.mlir with FileCheck negative tests covering each rejected case (address-space change / alignment widening / swizzle change).