KhronosGroup / KhronosGroup/SPIRV-LLVM-Translator

OpSource parsing does not account for optional parameters

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

Description

```llvm
%1 = OpString "test"
OpSource Unknown 0 %1
%2 = OpString "test"
```
Running `llvm-spirv -r ./test.spv --spirv-debug` prints:
```
addCapability: Kernel
Read word: W = 119734787 V = 119734787
Read word: W = 66560 V = 66560
Read word: W = 458752 V = 458752
Read word: W = 3 V = 3
Read word: W = 0 V = 0
Read word: W = 262151 V = 262151
[SPIRVDecoder] getWordCountAndOpCode 4 String
Read word: W = 1 V = 1
Read string: "test"
Read word: W = 262147 V = 262147
[SPIRVDecoder] getWordCountAndOpCode 4 Source
Read word: W = 0 V = 0
Read word: W = 0 V = 0
Read word: W = 1 V = 1
[SPIRVDecoder] getWordCountAndOpCode 0 Undef
Read word: W = 262151 V = 262151
[SPIRVDecoder] getWordCountAndOpCode 4 String
Read word: W = 2 V = 2
Read string: "test"
Read word: W = 32664 V = 32664
[SPIRVDecoder] getWordCountAndOpCode FAIL 0 0
```
It fails to consider that `OpSource` accepts optional operands, and then tries to parse the optional parameter as an instruction.

Contributor guide

Open the contributing guide

Research direction

Start at the SPIRVDecoder handling for OpSource and reproduce the issue with llvm-spirv -r ./test.spv --spirv-debug. Done means the optional OpSource operands are consumed as part of that instruction and the following OpString is parsed normally instead of as an instruction.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.