<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/149130>149130</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang][x86-64] Assertion failure in CastInst::Create (“Invalid cast!”)
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
BKUS21
</td>
</tr>
</table>
<pre>
Compiler Explorer: https://godbolt.org/z/cWrYdKjfa
Generated by fuzzer.
Console output:
```
clang-22: /root/llvm-project/llvm/lib/IR/Instructions.cpp:3037: static llvm::CastInst* llvm::CastInst::Create(llvm::Instruction::CastOps, llvm::Value*, llvm::Type*, const llvm::Twine&, llvm::InsertPosition): Assertion `castIsValid(op, S, Ty) && "Invalid cast!"' 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-20250716/bin/clang-22 -cc1 -triple x86_64-unknown-linux-gnu -O2 -emit-obj -dumpdir /app/output.s- -disable-free -clear-ast-before-backend -main-file-name example.c -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -fno-verbose-asm -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debug-info-kind=constructor -dwarf-version=4 -debugger-tuning=gdb -fdebug-compilation-dir=/app -fcoverage-compilation-dir=/app -resource-dir /opt/compiler-explorer/clang-assertions-trunk-20250716/lib/clang/22 -internal-isystem /opt/compiler-explorer/clang-assertions-trunk-20250716/lib/clang/22/include -internal-isystem /usr/local/include -internal-isystem /opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/16.0.0/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcolor-diagnostics -vectorize-loops -vectorize-slp -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/example-a1cf0e.o -x c <source>
1. <source>:7:1: current parser token 'int'
2. <source>:3:5: LLVM IR generation of declaration 'crash'
3. <source>:3:5: Generating code for declaration 'crash'
#0 0x0000000003fb2168 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk-20250716/bin/clang-22+0x3fb2168)
#1 0x0000000003faf014 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
#2 0x0000779ba5242520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#3 0x0000779ba52969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
#4 0x0000779ba5242476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
#5 0x0000779ba52287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
#6 0x0000779ba522871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
#7 0x0000779ba5239e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#8 0x00000000038ab304 (/opt/compiler-explorer/clang-assertions-trunk-20250716/bin/clang-22+0x38ab304)
#9 0x000000000436cfcb llvm::IRBuilderBase::CreateCast(llvm::Instruction::CastOps, llvm::Value*, llvm::Type*, llvm::Twine const&, llvm::MDNode*, llvm::FMFSource) (.constprop.0) CGExprScalar.cpp:0:0
#10 0x000000000438a32f (anonymous namespace)::ScalarExprEmitter::VisitCastExpr(clang::CastExpr*) CGExprScalar.cpp:0:0
#11 0x0000000004382581 clang::StmtVisitorBase<std::add_pointer, (anonymous namespace)::ScalarExprEmitter, llvm::Value*>::Visit(clang::Stmt*) CGExprScalar.cpp:0:0
#12 0x000000000438699c clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) (/opt/compiler-explorer/clang-assertions-trunk-20250716/bin/clang-22+0x438699c)
#13 0x000000000448b4bc clang::CodeGen::CodeGenFunction::EmitReturnStmt(clang::ReturnStmt const&) (/opt/compiler-explorer/clang-assertions-trunk-20250716/bin/clang-22+0x448b4bc)
#14 0x0000000004493bee clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/opt/compiler-explorer/clang-assertions-trunk-20250716/bin/clang-22+0x4493bee)
#15 0x000000000449baec clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) (/opt/compiler-explorer/clang-assertions-trunk-20250716/bin/clang-22+0x449baec)
#16 0x0000000004502bfe clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) (/opt/compiler-explorer/clang-assertions-trunk-20250716/bin/clang-22+0x4502bfe)
#17 0x00000000045148f4 clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/opt/compiler-explorer/clang-assertions-trunk-20250716/bin/clang-22+0x45148f4)
#18 0x000000000457f76d clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk-20250716/bin/clang-22+0x457f76d)
#19 0x000000000457a774 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk-20250716/bin/clang-22+0x457a774)
#20 0x000000000457ae13 clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/opt/compiler-explorer/clang-assertions-trunk-20250716/bin/clang-22+0x457ae13)
#21 0x00000000045859a3 clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (.part.0) CodeGenModule.cpp:0:0
#22 0x000000000496b6d0 (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) ModuleBuilder.cpp:0:0
#23 0x000000000495ad04 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/opt/compiler-explorer/clang-assertions-trunk-20250716/bin/clang-22+0x495ad04)
#24 0x000000000665c804 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk-20250716/bin/clang-22+0x665c804)
#25 0x0000000004967388 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk-20250716/bin/clang-22+0x4967388)
#26 0x0000000004c5ad75 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk-20250716/bin/clang-22+0x4c5ad75)
#27 0x0000000004bd782e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk-20250716/bin/clang-22+0x4bd782e)
#28 0x0000000004d4e821 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk-20250716/bin/clang-22+0x4d4e821)
#29 0x0000000000d933bf cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk-20250716/bin/clang-22+0xd933bf)
#30 0x0000000000d89f9a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#31 0x0000000000d8e6b9 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk-20250716/bin/clang-22+0xd8e6b9)
#32 0x0000000000c44414 main (/opt/compiler-explorer/clang-assertions-trunk-20250716/bin/clang-22+0xc44414)
#33 0x0000779ba5229d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#34 0x0000779ba5229e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#35 0x0000000000d89a45 _start (/opt/compiler-explorer/clang-assertions-trunk-20250716/bin/clang-22+0xd89a45)
clang: error: unable to execute command: Aborted (core dumped)
clang: error: clang frontend command failed due to signal (use -v to see invocation)
Compiler returned: 254
```
Code:
```c
typedef long double vec __attribute__((vector_size(16)));
__attribute__((noinline))
vec crash(vec x) {
vec y;
return x < y;
}
int main(void) {
return 0;
}
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzMWt9z3KiT_2vwC8WUhKQZ6cEP8ownm9rkNhXnsnVPUwiQzFoCFSDHzl9_BWgiaTz54dzO1XfL63gYuvvzaZruFoIYIxrJ-TXIbkC2uyKDvVf6-ubP_77D8VWl2PP1VnW9aLmGt099qzTXICnhvbW9AUkJ8B7gfaNYpVq7UroBeP8V4D39W_8P-_OfmoCoBFH5hkuuieUMVs-wHr5-5XoVvtkqaVTLoRpsP1in0Q-DdTT-RCVtiWwQxs4uwHutlAV437aPHeq1-ofT40f3j6gA3r_96H5JY_VArVDSrGjfg6RMomTjtBhLrKDQyyQlSMotMdbNB7g8Nxo-aU4sBzifJsxMTBJ_9Qbg7UzNZ9IOHOByOfrpuT8OUiWNnX_1RUgO8Hop8FYaru0HZYS3hwvHpDRuUCgJwTqiDq_5TFrBAM5V7-Tv3K9PzwAX0GtcQ4DxW_noJkEnAHAMMAZ4A2siWs7cunx4d1ve3UIzVJ2wkMBqaKDmvdIWWnW69sLeD9WKqm62Csu1EcYM3AC8h0QyKCRtB8ahveeQamLuYUXog9WEcoe117zXinJjOINGDToMO0lijKLCh5EeJDRUi946vHeW0AfIhq4PARStQFR80KrRpINEN0PHpTVj_KjeYaJjVCN-jGq8D4FGji41yOpBPiAc4SzaxGuA95WQ3-ZhDBGlMURWi77l8ClfH9YpGuSDVF8kaoUcnlAjB4j-whDxTlikqn8gcjCZ0A4K6XsHyIf-yiCImDCkajmqNecQ0ZYTjYixqOK10hw5R3HJIOqIkKgWLUeSdBzyJ9L1LV9RiDrNW0WJw486xXgLe0Eh6gVFLX_kLcThgzCoFxyirtak46hXQlq3tXdSSQ5R3RF7j7jWUkFU1z2iSrolsiDZKQlRLRXSapBMyAa5uWHoketKGY6I6SDqfFy7_aE0Iq0ghhuI6kF-EZIh64gakOwwRJbohltE-8F5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