<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/63548>63548</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            clang: Assertion `castIsValid(op, S, Ty) && "Invalid cast!"' failed.
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          wierton
      </td>
    </tr>
</table>

<pre>
    The testcase (with option `-O0`):
```
typedef long double T __attribute__((vector_size(32)));

T sum(T first, T second) { return first > second; }
```

```
$ clang --version
clang version 17.0.0 (https://github.com/llvm/llvm-project.git 12e9c7aaa66b7624b5d7666ce2794d912bf9e4b7)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/compiler-explorer/clang-assertions-trunk/bin
Compiler returned: 0
$ clang -O0 small.c
clang: /root/llvm-project/llvm/lib/IR/Instructions.cpp:3447: static llvm::CastInst* llvm::CastInst::Create(llvm::Instruction::CastOps, llvm::Value*, llvm::Type*, const llvm::Twine&, llvm::Instruction*): 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/bin/clang -gdwarf-4 -g -o /app/output.s -S --gcc-toolchain=/opt/compiler-explorer/gcc-9.2.0 -fcolor-diagnostics -fno-crash-diagnostics -O0 <source>
1.      <eof> parser at end of file
2.      <source>:3:3: LLVM IR generation of declaration 'sum'
3.      <source>:3:3: Generating code for declaration 'sum'
 #0 0x0000555803384f2f llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3c52f2f)
 #1 0x0000555803382c9c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3c50c9c)
 #2 0x00005558032cd398 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007f627e805420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #4 0x00007f627e2d200b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
 #5 0x00007f627e2b1859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
 #6 0x00007f627e2b1729 (/lib/x86_64-linux-gnu/libc.so.6+0x22729)
 #7 0x00007f627e2c2fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
 #8 0x0000555802cba01f (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x358801f)
 #9 0x000055580087244c llvm::IRBuilderBase::CreateCast(llvm::Instruction::CastOps, llvm::Value*, llvm::Type*, llvm::Twine const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x114044c)
#10 0x0000555803ad156c (anonymous namespace)::ScalarExprEmitter::VisitCastExpr(clang::CastExpr*) CGExprScalar.cpp:0:0
#11 0x0000555803acd224 clang::StmtVisitorBase<std::add_pointer, (anonymous namespace)::ScalarExprEmitter, llvm::Value*>::Visit(clang::Stmt*) CGExprScalar.cpp:0:0
#12 0x0000555803ad4eb4 clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x43a2eb4)
#13 0x00005558036a7714 clang::CodeGen::CodeGenFunction::EmitReturnStmt(clang::ReturnStmt const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3f75714)
#14 0x00005558036aeb7b clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3f7cb7b)
#15 0x00005558036b52d4 clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3f832d4)
#16 0x000055580371526a clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3fe326a)
#17 0x0000555803728e9f clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3ff6e9f)
#18 0x000055580378de09 clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x405be09)
#19 0x0000555803788db5 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4056db5)
#20 0x0000555803789988 clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4057988)
#21 0x00005558037927d3 clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (.part.0) CodeGenModule.cpp:0:0
#22 0x0000555804601ac6 (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) ModuleBuilder.cpp:0:0
#23 0x00005558045f3b70 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4ec1b70)
#24 0x0000555805afbe14 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x63c9e14)
#25 0x00005558045fe9a8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4ecc9a8)
#26 0x0000555803e48b79 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4716b79)
#27 0x0000555803dce4c6 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x469c4c6)
#28 0x0000555803f2d2a6 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x47fb2a6)
#29 0x00005558008270ed cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x10f50ed)
#30 0x0000555800822dea ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#31 0x0000555803c2d23d 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
#32 0x00005558032cd8a0 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3b9b8a0)
#33 0x0000555803c2d85f 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
#34 0x0000555803bf49ec clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x44c29ec)
#35 0x0000555803bf547d 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+0x44c347d)
#36 0x0000555803bfd55d clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x44cb55d)
#37 0x000055580082534a clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x10f334a)
#38 0x000055580072b5c5 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xff95c5)
#39 0x00007f627e2b3083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#40 0x000055580081dbce _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x10ebbce)
clang: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzkWltv2zoS_jXKC2GDInV9yIPjJN0e9KBFE3QfDV5GDrcyKZBUmuyvX1CSE9Fxcpoed7HAAk0a8TKc7-NwZnhhzqmtBjhP8oskvzxjvb8z9vyHAuuNPuNGPp7f3gHy4LxgDlBCqh_K3yHTeWU0Sgq8-IyTAiekTugqwZcJXoXP8d_w6R87kNCg1ugtkqbnLaBbtNkw763ivYfNJiFVQqp7EN7YjVP_hoRUlASZ4z96MUkeft8i1-8SUt2iRlnnE7JGt8iBMFompEZJeYEs-N7qsR4l9GpfTS9QUl4eVfN4IcmQaJneosXiHqxTRo8VY-FUhNJyiZc4kHPnfecCE-Q6Iddb5e96vhRml5Drtr3f_7forPkXCL_cKo9SArUoGWNFwcuCZDyXZVEUAkhZZ7JOCW9qyHgZiBjxM7sFn9AVeqiKTZEtev1dmx960SrdPyy2up_a3VlgEu2MhDa07oxTD2PVR-08a1uQl8qGqoRcm84n5FqYXadasAt46FpjwYaygHXBnAMbJt0tvO3194RcczWxsZ56TbyDDDJfUvgZI7djbbsUMxKn4a0x_oCdGWeKJ-T649fwSztvezEoshRdl9AVzbIySHGeeSXQ0IeuErpaM-dD-4SsjpWOXxaYD_b23GA2xHOPz50Lhvbc6htre0jIKi69fez2hcJo5-dVP5SGhBRxh_lgoV9YRmi15zosMBH0dd9Yq2RCKtOF_jeD0T8O5h4kFigh5KO-D41Q6JCQNCEkISVqmGpBLkfGv3y6Wt1cIdfznfKIId5vkYXOWI-8Qe8z3oRcK-d6cAm5RkxLpLR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