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

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

    <tr>
      <th>Labels</th>
      <td>
            clang
      </td>
    </tr>

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

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

<pre>
    Compiler explorer: https://godbolt.org/z/49K9Pd5x7.

The following program `small.c` triggers a crash in clang-18:

``` sh
% cat small.c
int main (void)
{
  double x, r;

  __asm __volatile__ ("fsqrt" : "=t" (r) : "0" (x && x));

  return r;
}


% clang -O0 small.c
clang: /root/llvm-project/llvm/lib/IR/Instructions.cpp:3314: 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 -mllvm --x86-asm-syntax=intel -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>:1:5: LLVM IR generation of declaration 'main'
3.  <source>:1:5: Generating code for declaration 'main'
 #0 0x000000000372dd18 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x372dd18)
 #1 0x000000000372b9dc llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x372b9dc)
 #2 0x00000000036742f8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007f2b29de3420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #4 0x00007f2b298a600b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
 #5 0x00007f2b29885859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
 #6 0x00007f2b29885729 (/lib/x86_64-linux-gnu/libc.so.6+0x22729)
 #7 0x00007f2b29896fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
 #8 0x000000000307e2ca (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x307e2ca)
 #9 0x0000000000dc5dfe llvm::IRBuilderBase::CreateCast(llvm::Instruction::CastOps, llvm::Value*, llvm::Type*, llvm::Twine const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xdc5dfe)
#10 0x0000000003a44a36 clang::CodeGen::CodeGenFunction::EmitAsmStmt(clang::AsmStmt const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3a44a36)
#11 0x0000000003a4854b clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3a4854b)
#12 0x0000000003a4e87c clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3a4e87c)
#13 0x0000000003aadde6 clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3aadde6)
#14 0x0000000003ac0e8a clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3ac0e8a)
#15 0x0000000003b21c83 clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3b21c83)
#16 0x0000000003b1ce55 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3b1ce55)
#17 0x0000000003b1d41b clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3b1d41b)
#18 0x0000000003b26783 clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (.part.0) CodeGenModule.cpp:0:0
#19 0x000000000499a9b6 (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) ModuleBuilder.cpp:0:0
#20 0x000000000498ba78 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x498ba78)
#21 0x0000000005e9b4d4 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x5e9b4d4)
#22 0x00000000049982a8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x49982a8)
#23 0x00000000041fc4f9 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x41fc4f9)
#24 0x000000000417d9ce clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x417d9ce)
#25 0x00000000042db54e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x42db54e)
#26 0x0000000000bef0e6 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xbef0e6)
#27 0x0000000000be69aa ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#28 0x0000000003fd9c19 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
#29 0x00000000036747a4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x36747a4)
#30 0x0000000003fda20f 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
#31 0x0000000003fa23d5 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3fa23d5)
#32 0x0000000003fa2e3d 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+0x3fa2e3d)
#33 0x0000000003faad65 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3faad65)
#34 0x0000000000bec58c clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xbec58c)
#35 0x0000000000ae6751 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xae6751)
#36 0x00007f2b29887083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#37 0x0000000000be648e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xbe648e)
clang: error: clang frontend command failed with exit code 134 (use -v to see invocation)
```

Clang version:

```
clang version 18.0.0 (https://github.com/llvm/llvm-project.git f2b79ed9c6c858426b15a0374103ab901b5b2ef3)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/compiler-explorer/clang-assertions-trunk/bin
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzkWt9z26q2_mvIC2OPhH4_5MFxkt7u2z3tNJneRw8CpHCLQAdQ6py__gxCjoXidCfd7pkzczppYiNY6_s-FqwlJGwMbyVjlyC7Atn1BR7sg9KXREnZCsEvakWfLreq67lgGrJ9L5RmGiQb-GBtb0CyAegWoNtW0VoJu1a6Bej2nwDdptX_Vl9oti_WILoG0cb_vn9gsFFCqB9ctrDXqtW4gyCPTIeFWBOQR9Bq3rZMG4gh0dg8QC4hEVi2q7h0DmfmQB75H2gephaUQYItPNgbG7m0sMNcQoDKR8UpQNXUu7jyHyCkaqgFg3uAtlCD5GruBsLdDpsO7naPSmDLBdvtnC2AUGP-oS1ACDpNAEIgufZfUakBqg7N0dS2hwDlAOXOT-V-lo40s4OWcwTFdcD4yNJJAlefo5Dr2Oy93mqlLEC3Qjx2q16r_2fk8NX94TVAtx-_ul_SWD0Qy5U0a9L3INkkSZw6K8ZiywkcxyQbkGy22FjXH6DNqVb_TTNsGUDlscPMxXHE5944uY-9vmExMIA2Yev9U39oJEoaO7_0g0s2SjofMHfmxlWOycYYpl2TCzfi8JpvWLhgKFXvxt-5X_dP46z5SQIIfZSPrhN0AwCK3QyjAjaYC0anyP7y6WZzdwPNUHfcQgzroYWa9UpbaNVynXD7MNRrorrZRITTw40ZmAHoFmJJIZdEDJRB-8Cm1VBj8t1qTJiD22vWa0WYMYxCowbtm91IbIwiHFtGoR4kNETz3k6Q7ywm3yEduv55QUVrCL9M6xHrduiYtGaKI9U7YGTaBlbP2wC69esSH6Q1K6sH-R2g25rLw2W4aukPrJtVClctXClnEfe9szvYfrBrA1edEwGuVvsyX2HTrcyTtHgPkmsuLRNwdQdXq5aQlVVKkAfMJUiufwrMda7WaB3BVUOUUHpFOW6lMpYTA1eNVKtRzrD5cwRBsp10TG68MvEaulamGpDcwB5rwzTEFjJJoWpgwwXzHdE6HJ1sYpBsMifip0_f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