Issue 244340
Summary [HLSL][Matrix] Crash on `+` or `-` between a matrix and a scalar when either side is a multiply
Labels new issue
Assignees kmpeng
Reporter kmpeng
    Clang crashes with an assertion when a `+` or `-` combines a matrix with a scalar and either side is a multiply. For example, `3 - 2 * m`, `m * 2 + 3`, or `m[0][0] * 2 + m`.

Repro:
https://godbolt.org/z/xx59zhGjh
```hlsl
export float2x3 fn(float2x3 m) {
  return 3 - 2 * m;
}
```
```
clang: warning: argument unused during compilation: '-Qembed_debug' [-Wunused-command-line-argument]
clang: /root/llvm-project/llvm/lib/IR/Instructions.cpp:804: void llvm::CallInst::init(llvm::FunctionType*, llvm::Value*, llvm::ArrayRef<llvm::Value*>, llvm::ArrayRef<llvm::OperandBundleDefT<llvm::Value*> >, const llvm::Twine&): Assertion `(i >= FTy->getNumParams() || FTy->getParamType(i) == Args[i]->getType()) && "Calling a function with a bad signature!"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and dumped files.
Stack dump:
0.	Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/clang --driver-mode=dxc -Zi -Qembed_debug -Fc /app/output.s -fcolor-diagnostics -fno-crash-diagnostics -T lib_6_6 <source>
1.	<eof> parser at end of file
2.	<source>:1:1: LLVM IR generation of declaration
3.	<source>:1:17: Generating code for declaration 'fn'
 #0 0x0000000004f94f78 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4f94f78)
 #1 0x0000000004f921d4 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4f921d4)
 #2 0x0000000004f9280c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4f9280c)
 #3 0x0000000004ecb7c8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #4 0x00007f3a7b845330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
 #5 0x00007f3a7b89ec0c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x9ec0c)
 #6 0x00007f3a7b84527e raise (/lib/x86_64-linux-gnu/libc.so.6+0x4527e)
 #7 0x00007f3a7b8288ff abort (/lib/x86_64-linux-gnu/libc.so.6+0x288ff)
 #8 0x00007f3a7b82881b (/lib/x86_64-linux-gnu/libc.so.6+0x2881b)
 #9 0x00007f3a7b83b517 (/lib/x86_64-linux-gnu/libc.so.6+0x3b517)
#10 0x00000000047e9ccf llvm::CallInst::init(llvm::FunctionType*, llvm::Value*, llvm::ArrayRef<llvm::Value*>, llvm::ArrayRef<llvm::OperandBundleDefT<llvm::Value*>>, llvm::Twine const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x47e9ccf)
#11 0x0000000001a765b0 llvm::IRBuilderBase::CreateCall(llvm::FunctionType*, llvm::Value*, llvm::ArrayRef<llvm::Value*>, llvm::Twine const&, llvm::MDNode*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x1a765b0)
#12 0x00000000054e19b3 buildFMulAdd(llvm::Instruction*, llvm::Value*, clang::CodeGen::CodeGenFunction const&, clang::CodeGen::CGBuilderTy&, bool, bool) CGExprScalar.cpp:0:0
#13 0x00000000054ed6a9 (anonymous namespace)::ScalarExprEmitter::EmitSub((anonymous namespace)::BinOpInfo const&) CGExprScalar.cpp:0:0
#14 0x00000000054f5184 clang::StmtVisitorBase<std::add_pointer, (anonymous namespace)::ScalarExprEmitter, llvm::Value*>::Visit(clang::Stmt*) CGExprScalar.cpp:0:0
#15 0x00000000054f9c5c clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x54f9c5c)
#16 0x0000000005621c9d clang::CodeGen::CodeGenFunction::EmitReturnStmt(clang::ReturnStmt const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x5621c9d)
#17 0x0000000005631c6b clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x5631c6b)
#18 0x000000000569dac6 clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x569dac6)
#19 0x00000000056afb3c clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x56afb3c)
#20 0x000000000571fc7a clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x571fc7a)
#21 0x0000000005719345 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x5719345)
#22 0x0000000005719cc3 clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x5719cc3)
#23 0x0000000005727221 clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (.part.0) CodeGenModule.cpp:0:0
#24 0x000000000572844f clang::CodeGen::CodeGenModule::EmitDeclContext(clang::DeclContext const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x572844f)
#25 0x0000000005727294 clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (.part.0) CodeGenModule.cpp:0:0
#26 0x0000000005aa0729 (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) ModuleBuilder.cpp:0:0
#27 0x0000000005a943b4 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x5a943b4)
#28 0x00000000090b62b4 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x90b62b4)
#29 0x0000000005a9d078 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x5a9d078)
#30 0x0000000005de5f73 clang::HLSLFrontendAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x5de5f73)
#31 0x0000000005dc7e58 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x5dc7e58)
#32 0x0000000005d543bd clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x5d543bd)
#33 0x0000000005e9e403 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x5e9e403)
#34 0x00000000017248f8 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x17248f8)
#35 0x000000000171b7fa ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>) driver.cpp:0:0
#36 0x000000000171b983 int llvm::function_ref<int (llvm::SmallVectorImpl<char const*>&)>::callback_fn<clang_main(int, char**, llvm::ToolContext const&)::'lambda'(llvm::SmallVectorImpl<char const*>&)>(long, llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#37 0x0000000005b168f9 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::'lambda'()>(long) Job.cpp:0:0
#38 0x0000000004ecbbc4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4ecbbc4)
#39 0x0000000005b17465 clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0
#40 0x0000000005ad4282 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x5ad4282)
#41 0x0000000005ad753c clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x5ad753c)
#42 0x0000000005ae3a35 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x5ae3a35)
#43 0x0000000001720f4a clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x1720f4a)
#44 0x00000000016ac803 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x16ac803)
#45 0x00007f3a7b82a1ca (/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
#46 0x00007f3a7b82a28b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
#47 0x000000000171b1a5 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x171b1a5)
clang: error: clang frontend command failed due to signal (use -v to see invocation)
Program terminated with signal SIGABRT (6)
Compiler returned: 134
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to