<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/153513>153513</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[HLSL][SPIR-V] Hitting assert when compiling program with 'asdouble' in HLSL
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
kmpeng
</td>
</tr>
</table>
<pre>
https://godbolt.org/z/qzj6PsWPz
Discovered while running the offload-test-suite. Hitting an assert when compiling this program with spirv:
```hlsl
StructuredBuffer<uint4> Low : register(t0);
StructuredBuffer<uint4> High : register(t1);
RWStructuredBuffer<double4> Out : register(u2);
[numthreads(1,1,1)]
void main() {
Out[0] = asdouble(Low[0], High[0]);
}
```
```
Assertion `DstType->getNumElements() >= SrcType->getNumElements()' failed
```
https://github.com/llvm/llvm-project/blob/8432f24831b21c34eb8c03b7cdc75c6f59326395/llvm/lib/Target/SPIRV/SPIRVLegalizePointerCast.cpp#L191
Crash stack:
```
Stack dump:
0. Program arguments: ../llvm-build-debug/bin/clang-dxc -spirv -fspv-target-env=vulkan1.3 -T cs_6_5 clang/test/CodeGenHLSL/builtins/TestFile.hlsl
1. <eof> parser at end of file
2. Code generation
3. Running pass 'Function Pass Manager' on module 'clang/test/CodeGenHLSL/builtins/TestFile.hlsl'.
4. Running pass 'SPIRV legalize bitcast pass' on function '@main'
#0 0x00005fe7d787e7a1 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/kaitlinpeng/llvm-project/llvm/lib/Support/Unix/Signals.inc:834:11
#1 0x00005fe7d787ed2b PrintStackTraceSignalHandler(void*) /home/kaitlinpeng/llvm-project/llvm/lib/Support/Unix/Signals.inc:918:1
#2 0x00005fe7d787ca76 llvm::sys::RunSignalHandlers() /home/kaitlinpeng/llvm-project/llvm/lib/Support/Signals.cpp:104:5
#3 0x00005fe7d787e01e llvm::sys::CleanupOnSignal(unsigned long) /home/kaitlinpeng/llvm-project/llvm/lib/Support/Unix/Signals.inc:374:1
#4 0x00005fe7d779fc87 (anonymous namespace)::CrashRecoveryContextImpl::HandleCrash(int, unsigned long) /home/kaitlinpeng/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:0:7
#5 0x00005fe7d77a0075 CrashRecoverySignalHandler(int) /home/kaitlinpeng/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:391:1
#6 0x000074aae0845330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
#7 0x000074aae089eb2c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x9eb2c)
#8 0x000074aae084527e raise (/lib/x86_64-linux-gnu/libc.so.6+0x4527e)
#9 0x000074aae08288ff abort (/lib/x86_64-linux-gnu/libc.so.6+0x288ff)
#10 0x000074aae082881b (/lib/x86_64-linux-gnu/libc.so.6+0x2881b)
#11 0x000074aae083b517 (/lib/x86_64-linux-gnu/libc.so.6+0x3b517)
#12 0x00005fe7d56e65d0 (anonymous namespace)::SPIRVLegalizePointerCast::storeVectorFromVector(llvm::IRBuilder<llvm::ConstantFolder, llvm::IRBuilderDefaultInserter>&, llvm::Value*, llvm::Value*, llvm::Align) /home/kaitlinpeng/llvm-project/llvm/lib/Target/SPIRV/SPIRVLegalizePointerCast.cpp:193:20
#13 0x00005fe7d56e5a34 (anonymous namespace)::SPIRVLegalizePointerCast::transformStore(llvm::IRBuilder<llvm::ConstantFolder, llvm::IRBuilderDefaultInserter>&, llvm::Instruction*, llvm::Value*, llvm::Value*, llvm::Align) /home/kaitlinpeng/llvm-project/llvm/lib/Target/SPIRV/SPIRVLegalizePointerCast.cpp:267:7
#14 0x00005fe7d56e5681 (anonymous namespace)::SPIRVLegalizePointerCast::legalizePointerCast(llvm::IntrinsicInst*) /home/kaitlinpeng/llvm-project/llvm/lib/Target/SPIRV/SPIRVLegalizePointerCast.cpp:315:11
#15 0x00005fe7d56e51a4 (anonymous namespace)::SPIRVLegalizePointerCast::runOnFunction(llvm::Function&) /home/kaitlinpeng/llvm-project/llvm/lib/Target/SPIRV/SPIRVLegalizePointerCast.cpp:342:28
#16 0x00005fe7d6fe00ca llvm::FPPassManager::runOnFunction(llvm::Function&) /home/kaitlinpeng/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1398:23
#17 0x00005fe7d6fe4aa2 llvm::FPPassManager::runOnModule(llvm::Module&) /home/kaitlinpeng/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1444:16
#18 0x00005fe7d6fe097b (anonymous namespace)::MPPassManager::runOnModule(llvm::Module&) /home/kaitlinpeng/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1513:23
#19 0x00005fe7d6fe04fa llvm::legacy::PassManagerImpl::run(llvm::Module&) /home/kaitlinpeng/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:531:16
#20 0x00005fe7d6fe4d81 llvm::legacy::PassManager::run(llvm::Module&) /home/kaitlinpeng/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1640:3
#21 0x00005fe7d8721d24 (anonymous namespace)::EmitAssemblyHelper::RunCodegenPipeline(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>&, std::unique_ptr<llvm::ToolOutputFile, std::default_delete<llvm::ToolOutputFile>>&) /home/kaitlinpeng/llvm-project/clang/lib/CodeGen/BackendUtil.cpp:1254:19
#22 0x00005fe7d871b74e (anonymous namespace)::EmitAssemblyHelper::emitAssembly(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) /home/kaitlinpeng/llvm-project/clang/lib/CodeGen/BackendUtil.cpp:1280:7
#23 0x00005fe7d871ac38 clang::emitBackendOutput(clang::CompilerInstance&, clang::CodeGenOptions&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) /home/kaitlinpeng/llvm-project/clang/lib/CodeGen/BackendUtil.cpp:1443:3
#24 0x00005fe7d8742851 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) /home/kaitlinpeng/llvm-project/clang/lib/CodeGen/CodeGenAction.cpp:316:3
#25 0x00005fe7db6a00b8 clang::ParseAST(clang::Sema&, bool, bool) /home/kaitlinpeng/llvm-project/clang/lib/Parse/ParseAST.cpp:190:12
#26 0x00005fe7d904cac3 clang::ASTFrontendAction::ExecuteAction() /home/kaitlinpeng/llvm-project/clang/lib/Frontend/FrontendAction.cpp:1430:1
#27 0x00005fe7d87467b0 clang::CodeGenAction::ExecuteAction() /home/kaitlinpeng/llvm-project/clang/lib/CodeGen/CodeGenAction.cpp:1114:5
#28 0x00005fe7d904c436 clang::FrontendAction::Execute() /home/kaitlinpeng/llvm-project/clang/lib/Frontend/FrontendAction.cpp:1312:7
#29 0x00005fe7d8f645ce clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) /home/kaitlinpeng/llvm-project/clang/lib/Frontend/CompilerInstance.cpp:1066:23
#30 0x00005fe7d9256f57 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) /home/kaitlinpeng/llvm-project/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:299:8
#31 0x00005fe7d55109b8 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) /home/kaitlinpeng/llvm-project/clang/tools/driver/cc1_main.cpp:297:13
#32 0x00005fe7d5503892 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) /home/kaitlinpeng/llvm-project/clang/tools/driver/driver.cpp:223:5
#33 0x00005fe7d55043d0 clang_main(int, char**, llvm::ToolContext const&)::$_0::operator()(llvm::SmallVectorImpl<char const*>&) const /home/kaitlinpeng/llvm-project/clang/tools/driver/driver.cpp:366:9
#34 0x00005fe7d550439d int llvm::function_ref<int (llvm::SmallVectorImpl<char const*>&)>::callback_fn<clang_main(int, char**, llvm::ToolContext const&)::$_0>(long, llvm::SmallVectorImpl<char const*>&) /home/kaitlinpeng/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:46:5
#35 0x00005fe7d8dc0d51 llvm::function_ref<int (llvm::SmallVectorImpl<char const*>&)>::operator()(llvm::SmallVectorImpl<char const*>&) const /home/kaitlinpeng/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:69:5
#36 0x00005fe7d8dbdcb8 clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::$_0::operator()() const /home/kaitlinpeng/llvm-project/clang/lib/Driver/Job.cpp:436:34
#37 0x00005fe7d8dbdc85 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::$_0>(long) /home/kaitlinpeng/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:46:5
#38 0x00005fe7d639ce39 llvm::function_ref<void ()>::operator()() const /home/kaitlinpeng/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:69:5
#39 0x00005fe7d779fa7a llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) /home/kaitlinpeng/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:427:3
#40 0x00005fe7d8dbd61b clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const /home/kaitlinpeng/llvm-project/clang/lib/Driver/Job.cpp:436:7
#41 0x00005fe7d8d50fb3 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const /home/kaitlinpeng/llvm-project/clang/lib/Driver/Compilation.cpp:196:15
#42 0x00005fe7d8d511c4 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const /home/kaitlinpeng/llvm-project/clang/lib/Driver/Compilation.cpp:246:13
#43 0x00005fe7d8d6da42 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) /home/kaitlinpeng/llvm-project/clang/lib/Driver/Driver.cpp:2243:7
#44 0x00005fe7d5503375 clang_main(int, char**, llvm::ToolContext const&) /home/kaitlinpeng/llvm-project/clang/tools/driver/driver.cpp:404:9
#45 0x00005fe7d5537fe5 main /home/kaitlinpeng/llvm-build-debug/tools/clang/tools/driver/clang-driver.cpp:17:3
#46 0x000074aae082a1ca (/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
#47 0x000074aae082a28b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
#48 0x00005fe7d55020a5 _start (../llvm-build-debug/bin/clang-dxc+0x5c700a5)
clang-dxc: error: clang frontend command failed with exit code 134 (use -v to see invocation)
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzsW0tv47iy_jXMhrBBkXouslDs-HYGmdtBnOmzNCiJsnkiUz4klUf_-gtSlC0pT6eTvgPMGUzDjiiWvvqqWKwq0VQpvhaMnYLgDATzE9roTS1Pb7c7JtYnWV08nm603ilAUoAXAC_WdZHVlZ7Wcg3w4ifAi__8_Hd4pf519ROgFKB0zlVe3zHJCni_4RWDshGCizXUGwbrsqxqWkw0U3qiGq7ZFH7jWptxKiBVikkN7zdMwLze7njVTuQK7mS9lnQL77neQLXj8s5AQikIUfv_plIVQOlSyybXjWTFWVOWTAIya7jQPiDn8LK-h4CkULI1V5pJgGONAE4AOXtj5je-3jyZ6u2nApRe_-uZ-UXdZBWzEr43eiygwX0BIDgTzVZvJKOFAjj2AJ65fwkI5gCldzUv4JZyAXAMcAJBZKZCIxoEZwgEcwjIHFLVPhbg-LK-dyMAz6wS-z-7B0fzPomj76m1B68FBCGaK33zuG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