KhronosGroup / KhronosGroup/SPIRV-LLVM-Translator

SPIRVReader crashes when translating OpVariable with OpConstantSampler initializer

Open
#1,316 11 comments 0 reactions 0 assignees View on GitHub
Dominant language
LLVM
Stars
625
Forks
279
Avg merge
3d 5h
Merged PRs (30d)
34

Description

Below SPIRV code crashes in SPIRV Reader:
```
%2 = OpTypeSampler
%_ptr_UniformConstant_2 = OpTypePointer UniformConstant %2

%_sampler_init = OpConstantSampler %2 Clamp 0 Nearest
%image_sampler = OpVariable %_ptr_UniformConstant_2 UniformConstant %_sampler_init
```
The crash occurs during translation of `OpVariable`s initializer (`%_sampler_init`):
1. `%image_sampler` is translated to llvm `GlobalVariable`, since it's `OpVariable`:
```llvm
@image_sampler = external addrspace(2) constant %spirv.Sampler addrspace(2)*
```
2. `%_sampler_init` is `OpConstantSampler`, so it should be translated to:
```llvm
call %spirv.Sampler addrspace(2)* @__translate_sampler_initializer(i32 23)
```
But translation crashes because call instruction needs a `BasicBlock` which is `null`, because it's passed from `OpVariable` handling which operates globally.

I'm wondering how such case should be handled. The main problem is that `GlobalVariable` initializer must be `Constant`, but it actually isn't `Constant`, because `OpConstantSampler` is translated to `CallInst`.

Contributor guide

Open the contributing guide

Research direction

Start with the SPIRVReader paths for OpVariable and OpConstantSampler described in the report, and trace how the initializer is translated when no BasicBlock is available. Decide how this non-constant initializer should be represented without constructing a call in global scope. Done means the supplied SPIR-V no longer crashes and produces valid LLVM IR.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.