llvm / llvm/llvm-project

[HLSL][SPIRV] Backend crashes when handling atomic operations in a typed buffer

Open
#221,366 0 comments 0 reactions 1 assignee Claimed by @bob80905 View on GitHub
backend:SPIR-V clang:HLSL:SPIRV HLSL
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

We're generating code that crashes the backend when attempting to use atomic ops on a typed buffer ([godbolt](https://hlsl.godbolt.org/z/7PThsK7Y7)):
```hlsl
RWBuffer TBufU : register(u0);

[numthreads(64, 1, 1)]
void main(uint3 GTID : SV_GroupThreadID) {
InterlockedAnd(TBufU[0], 1ull);
}
```

The crash is in `SPIRVTargetLowering::enforcePtrTypeCompatibility` where we end up with a null pointer being passed into `MachineInstr::getOperand`:
```
* frame #0: 0x0000000101877f60 clang-dxc`llvm::MachineInstr::operands_impl(this=0x0000000000000000) at MachineInstr.h:362:13
frame #1: 0x0000000101866888 clang-dxc`llvm::MachineInstr::getOperand(this=0x0000000000000000, i=1) at MachineInstr.h:613:51
frame #2: 0x000000010186f924 clang-dxc`llvm::SPIRVGlobalRegistry::getResultType(this=0x000000011418a6b0, VReg=(Reg = 2147483665), MF=0x0000000b7cc55e00) at SPIRVGlobalRegistry.cpp:1383:37
frame #3: 0x00000001018f9998 clang-dxc`llvm::SPIRVTargetLowering::enforcePtrTypeCompatibility(this=0x0000000b7d5549e0, I=0x0000000b7d17cb60, PtrOpIdx=2, OpIdx=0) const at SPIRVISelLowering.cpp:720:30
frame #4: 0x00000001018f7e80 clang-dxc`llvm::SPIRVTargetLowering::finalizeLowering(this=0x0000000b7d5549e0, MF=0x0000000b7cc55e00) const at SPIRVISelLowering.cpp:561:13
```

Note that this does not happen with the equivalent code but using StructuredBuffer ([godbolt](https://hlsl.godbolt.org/z/94jqhzEez)).

We'll need further investigation to work out if this is a frontend or backend problem.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.