[SPIR-V] DXC crashed with asuint()
Description LLVM assertion failed.
Steps to Reproduce
dxc -T cs_6_0 -spirv path/to/file.hlsl
HLSL code:
RWSturcturedBuffer<uint> Out;
[numthreads(1, 1, 1)]
void main()
{
Out[0] = asuint(-1);
}
If we change the code as follows, the issue is not occurred.
Out[0] = asuint(-1 * 1);
Actual Behavior
Assertion failed: (SI.isSigned() == E->getType()->isSignedIntegerOrEnumerationType() && "Invalid evaluation result."), function Success, file ExprConstant.cpp, line 6199.
Environment
- DXC version: libdxcompiler.dylib: 1.8(dev;4640-45018c75)
- Host Operating System: Windows 11 23H2 and macOS 14.5
RWStructuredBuffer
Thanks for the issue! I bet this is similar to https://github.com/microsoft/DirectXShaderCompiler/issues/6712 We probably forward the layout for no reason.
Mmm not quite. For some reasons we lack an implicit cast in the AST, and thus we send a signed int to a function taking only an unsigned int. And we fail on an assert during the constant evaluation:
ExprConstant.cpp
assert(SI.isSigned() == E->getType()->isSignedIntegerOrEnumerationType() && "Invalid evaluation result.");
CallExpr 0x555555a75140 'unsigned int'
|-ImplicitCastExpr 0x555555a75128 'unsigned int (*)(int)' <FunctionToPointerDecay>
| `-DeclRefExpr 0x555555a750c0 'unsigned int (int)' lvalue Function 0x555555a74f20 'asuint' 'unsigned int (int)'
`-ImplicitCastExpr 0x555555a75170 'int' <IntegralCast>
`-UnaryOperator 0x555555a74eb8 'literal int' prefix '-'
`-IntegerLiteral 0x555555a74e98 'literal int' 1
And this issue also affects the DXIL side, as we fail in the frontend. Removing the SPIR-V tag.
As this only manifests as an assert, moving this to dormant. PR's fixing this would be gladly accepted!