<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/159176>159176</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[HLSL] Invalid aggregate expression assertion error when using arrays with `select`
</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/d31cT6q1a
```hlsl
StructuredBuffer<bool> Cond : register(t0);
StructuredBuffer<float2> TrueVal: register(t1);
StructuredBuffer<float2> FalseVal : register(t3);
RWStructuredBuffer<float2> Out : register(u5);
[numthreads(1,1,1)]
void main() {
float2 trueArray[2] = { TrueVal[0], TrueVal[1] };
float2 falseArray[2] = { FalseVal[0], FalseVal[1] };
float2 resultArray[2] = select(Cond[0], trueArray, falseArray);
Out[0] = resultArray[0];
Out[1] = resultArray[1];
}
```
This code produces this assertion error:
```
clang: /root/llvm-project/llvm/tools/clang/lib/CodeGen/CGExprAgg.cpp:2206: void clang::CodeGen::CodeGenFunction::EmitAggExpr(const clang::Expr*, clang::CodeGen::AggValueSlot): Assertion `E && hasAggregateEvaluationKind(E->getType()) && "Invalid aggregate expression to emit"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
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 cs_6_5 <source>
1. <eof> parser at end of file
2. <source>:9:6: LLVM IR generation of declaration 'main'
3. <source>:9:6: Generating code for declaration 'main'
#0 0x000000000417e408 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x417e408)
#1 0x000000000417b834 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x417b834)
#2 0x00000000040bfec8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#3 0x0000726302442520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x00007263024969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
#5 0x0000726302442476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
#6 0x00007263024287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
#7 0x000072630242871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
#8 0x0000726302439e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#9 0x00000000044fbec4 clang::CodeGen::CodeGenFunction::EmitAggExpr(clang::Expr const*, clang::CodeGen::AggValueSlot) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x44fbec4)
#10 0x0000000004a07f92 clang::CodeGen::CodeGenFunction::EmitExprAsInit(clang::Expr const*, clang::ValueDecl const*, clang::CodeGen::LValue, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4a07f92)
#11 0x0000000004a11620 clang::CodeGen::CodeGenFunction::EmitAutoVarInit(clang::CodeGen::CodeGenFunction::AutoVarEmission const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4a11620)
#12 0x0000000004a16d56 clang::CodeGen::CodeGenFunction::EmitVarDecl(clang::VarDecl const&) (.part.0) CGDecl.cpp:0:0
#13 0x0000000004a17567 clang::CodeGen::CodeGenFunction::EmitDecl(clang::Decl const&, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4a17567)
#14 0x0000000004656ccc clang::CodeGen::CodeGenFunction::EmitDeclStmt(clang::DeclStmt const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4656ccc)
#15 0x000000000466d48b clang::CodeGen::CodeGenFunction::EmitSimpleStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x466d48b)
#16 0x0000000004664c61 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4664c61)
#17 0x000000000466ceec clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x466ceec)
#18 0x00000000046d538e clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x46d538e)
#19 0x00000000046e7274 clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x46e7274)
#20 0x0000000004752f10 clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4752f10)
#21 0x000000000474dc04 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x474dc04)
#22 0x000000000474eaa0 clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x474eaa0)
#23 0x00000000047594e3 clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (.part.0) CodeGenModule.cpp:0:0
#24 0x0000000004abc5e0 (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) ModuleBuilder.cpp:0:0
#25 0x0000000004aab914 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4aab914)
#26 0x0000000006838f44 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x6838f44)
#27 0x0000000004ab7fd8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4ab7fd8)
#28 0x0000000004dd708e clang::HLSLFrontendAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4dd708e)
#29 0x0000000004db21c5 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4db21c5)
#30 0x0000000004d2d47e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4d2d47e)
#31 0x0000000004ea74fd clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4ea74fd)
#32 0x0000000000db5cbf cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xdb5cbf)
#33 0x0000000000dac92a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#34 0x0000000004b20f59 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
#35 0x00000000040c0364 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x40c0364)
#36 0x0000000004b2156f 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
#37 0x0000000004ae214d clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4ae214d)
#38 0x0000000004ae31de 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+0x4ae31de)
#39 0x0000000004aeb175 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4aeb175)
#40 0x0000000000db2145 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xdb2145)
#41 0x0000000000c63f94 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xc63f94)
#42 0x0000726302429d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#43 0x0000726302429e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#44 0x0000000000dac3d5 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xdac3d5)
clang: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzkWl9z4yj2_TTkhbJLQv_shzwoTpzp-WVq-tdJ9VTtiwsBkrVBoAWUTvbTbwGyZSlOOu5xz07VpuIqG3Ev5xyuuFcCrHVdCcYuQXIFkusL3JmtVJePTctEdVFI-nK5NabVIMoBWgO0riQtJDdzqSqA1v8GaE2jkDyk_woxCHKQBv5_yzUHQX5vVEdMpxi96sqSKRCtCik5iG7gSgoKQZRDxapaG6YAWpgAoCWIro5bllxig6ztg-rYV8yn1uHHrNeYa2v-avRobw-C_Msf7zr5vTNT-y45tLf_yZXoGrNVDFMN0CIEaNV_liC5BkH-JGsKG1wLgBYALSHIrDWEEPqRoFEdy5XCLyC5QiC5hiC6tr32EiRXgXWFVgctoeuYXXssB95Ky_you50mB_4OmqYOx14V0x03r9xqxhkxAC3sTB_4HSih1SGinXbW8--d6S2cq_EIztGka3i8a7jvatEfxCcI8odt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