[HLSL] RWBuffer of Matrix type errors correctly but also crashes
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
We error because it is illegal to have a RWBuffer of a matrix type. But the error should prevent us from proceeding to calling `createHostLayoutStructForBuffer` and it doesn't. Then we crash.
## Source
```hlsl
struct A {
RWBuffer Buf;
};
A a1 : register(u5);
A a2;
[numthreads(1,1,1)]
void main(uint3 ID : SV_GroupThreadID) {
int3x2 m = a1.Buf[ID.x];
a2.Buf[ID.x] = m;
}
```
https://godbolt.org/z/xce81b4Te
https://godbolt.org/z/n44oT7o1P
## Crash
```
#0 0x0000000004450f68 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4450f68)
#1 0x000000000444dd94 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x444dd94)
#2 0x000000000444e3b4 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x444e3b4)
#3 0x000000000438d758 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#4 0x000078fa4f242520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#5 0x000078fa4f2969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
#6 0x000078fa4f242476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
#7 0x000078fa4f2287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
#8 0x000078fa4f22871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
#9 0x000078fa4f239e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#10 0x000000000735338f createHostLayoutStructForBuffer(clang::Sema&, clang::HLSLBufferDecl*) SemaHLSL.cpp:0:0
#11 0x0000000007354f77 clang::SemaHLSL::ActOnEndOfTranslationUnit(clang::TranslationUnitDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x7354f77)
#12 0x0000000006e5d9cf clang::Sema::ActOnEndOfTranslationUnit() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x6e5d9cf)
#13 0x0000000006cc20aa clang::Parser::ParseTopLevelDecl(clang::OpaquePtr&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x6cc20aa)
#14 0x0000000006ca35ca clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x6ca35ca)
#15 0x0000000004f3c3e8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4f3c3e8)
#16 0x000000000527ad5d clang::HLSLFrontendAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x527ad5d)
#17 0x00000000052570e5 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x52570e5)
#18 0x00000000051d4bde clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x51d4bde)
#19 0x0000000005353a2d clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x5353a2d)
#20 0x0000000000de3a22 cc1_main(llvm::ArrayRef, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xde3a22)
#21 0x0000000000dda35a ExecuteCC1Tool(llvm::SmallVectorImpl&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr) driver.cpp:0:0
#22 0x0000000000dda4dd int llvm::function_ref&)>::callback_fn&)>(long, llvm::SmallVectorImpl&) driver.cpp:0:0
#23 0x0000000004fa55a9 void llvm::function_ref::callback_fn>, std::__cxx11::basic_string, std::allocator>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#24 0x000000000438db94 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x438db94)
#25 0x0000000004fa5bd6 clang::driver::CC1Command::Execute(llvm::ArrayRef>, std::__cxx11::basic_string, std::allocator>*, bool*) const (.part.0) Job.cpp:0:0
#26 0x0000000004f64cb2 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4f64cb2)
#27 0x0000000004f65c5e clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4f65c5e)
#28 0x0000000004f6d815 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4f6d815)
#29 0x0000000000ddfd84 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xddfd84)
#30 0x0000000000c97d7a main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xc97d7a)
#31 0x000078fa4f229d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#32 0x000078fa4f229e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#33 0x0000000000dd9df5 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xdd9df5)
```
Contributor guide
Research direction
Start by reproducing the provided HLSL source and inspect createHostLayoutStructForBuffer, called from SemaHLSL::ActOnEndOfTranslationUnit in SemaHLSL.cpp. Trace why the existing illegal RWBuffer matrix diagnostic does not stop this path; done means the diagnostic remains and compilation no longer crashes.
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
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 68/100