Issue 149130
Summary [clang][x86-64] Assertion failure in CastInst::Create (“Invalid cast!”)
Labels clang
Assignees
Reporter BKUS21
    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;
}

```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to