Skip to content

Fix crash when InferType fails on IntToPtr/AddrSpaceCast - #1654

Merged
rjodinchr merged 1 commit into
google:mainfrom
rjodinchr:main
Sep 25, 2026
Merged

rjodinchr merged 1 commit into
google:mainfrom
rjodinchr:main

Conversation

@rjodinchr

Copy link
Copy Markdown
Collaborator

When using physical storage buffers, PhysicalPointerArgsPass converts pointer kernel arguments into integers and inserts inttoptr instructions in the kernel entry block to cast them back to pointers.

If such a pointer is only passed to an undefined function declaration (such as in OpenCL CTS test link_error_returns_program), clspv's opaque pointer type inference cannot deduce the pointee type and InferType returns nullptr. In SPIRVProducerPass::GenerateInstruction, an assertion assert(Ty) caused the compiler to abort rather than reaching HandleDeferredInstruction to cleanly report the link error.

Similar to the fallback used in PhysicalPointerArgsPass, fall back to i32 when InferType cannot determine the pointee type for IntToPtr or AddrSpaceCast. The undefined function call is then safely deferred and subsequently caught and reported by HandleDeferredInstruction.

Add a regression test in test/PhysicalStorageBuffers/undefined_function.cl.

When using physical storage buffers, PhysicalPointerArgsPass converts
pointer kernel arguments into integers and inserts inttoptr instructions
in the kernel entry block to cast them back to pointers.

If such a pointer is only passed to an undefined function declaration
(such as in OpenCL CTS test `link_error_returns_program`), clspv's
opaque pointer type inference cannot deduce the pointee type and
InferType returns nullptr. In SPIRVProducerPass::GenerateInstruction,
an assertion `assert(Ty)` caused the compiler to abort rather than
reaching HandleDeferredInstruction to cleanly report the link error.

Similar to the fallback used in PhysicalPointerArgsPass, fall back to
i32 when InferType cannot determine the pointee type for IntToPtr or
AddrSpaceCast. The undefined function call is then safely deferred and
subsequently caught and reported by HandleDeferredInstruction.

Add a regression test in test/PhysicalStorageBuffers/undefined_function.cl.
@rjodinchr
rjodinchr merged commit c3b587c into google:main Sep 25, 2026
18 checks passed
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