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

    <tr>
        <th>Summary</th>
        <td>
            [clang] Instruction referencing instruction not embedded in a basic block!
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang:codegen,
            crash-on-valid,
            clang:frontend:fuzzer
      </td>
    </tr>

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

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

<pre>
    **This testcase is generated by a fuzzer.**

Compiler Explorer: [https://godbolt.org/z/8ob4qjW47](https://godbolt.org/z/8ob4qjW47)

This valid code will crash on clang assertion trunk:
```cpp
class S{
public:
  ~S() __attribute__((noreturn));
  void f();
};
extern bool check(const S&);
int test(bool value) {
  if (check(S()); check(S())) {
    return 1;
  }
  return 0;
}
```

It seems that this goes back to clang-3.8.

Stack dump:
```
Instruction referencing instruction not embedded in a basic block!
  %ref.tmp1 = alloca %class.S, align 1
  %call = invoke noundef zeroext addrspace(0) i1 @_Z5checkRK1S(ptr noundef nonnull align 1 dereferenceable(1) %ref.tmp1)
          to label %invoke.cont3 unwind label %lpad2, !dbg !22
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 -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics <source>
1.      <eof> parser at end of file
2.      Optimizer
3.      Running pass "verify" on module "<source>"
 #0 0x0000000003bf66c8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3bf66c8)
 #1 0x0000000003bf43cc llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3bf43cc)
 #2 0x0000000003b419c8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007cb33e842520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00000000035d9a21 (anonymous namespace)::Verifier::visitEHPadPredecessors(llvm::Instruction&) Verifier.cpp:0:0
 #5 0x00000000035f48ab (anonymous namespace)::Verifier::visitLandingPadInst(llvm::LandingPadInst&) Verifier.cpp:0:0
 #6 0x00000000035fcdcd llvm::InstVisitor<(anonymous namespace)::Verifier, void>::visit(llvm::Instruction&) Verifier.cpp:0:0
 #7 0x0000000003600d1d void llvm::InstVisitor<(anonymous namespace)::Verifier, void>::visit<llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::BasicBlock, true, false, void, false, void>, false, false>>(llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::BasicBlock, true, false, void, false, void>, false, false>, llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::BasicBlock, true, false, void, false, void>, false, false>) Verifier.cpp:0:0
 #8 0x0000000003602797 (anonymous namespace)::Verifier::verify(llvm::Function const&) Verifier.cpp:0:0
 #9 0x0000000003604181 llvm::verifyModule(llvm::Module const&, llvm::raw_ostream*, bool*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3604181)
#10 0x000000000360420d llvm::VerifierAnalysis::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x360420d)
#11 0x000000000524753c llvm::detail::AnalysisPassModel<llvm::Module, llvm::VerifierAnalysis, llvm::AnalysisManager<llvm::Module>::Invalidator>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x524753c)
#12 0x00000000035a7471 llvm::AnalysisManager<llvm::Module>::getResultImpl(llvm::AnalysisKey*, llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x35a7471)
#13 0x00000000035d9134 llvm::VerifierPass::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x35d9134)
#14 0x0000000003e927ee llvm::detail::PassModel<llvm::Module, llvm::VerifierPass, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3e927ee)
#15 0x00000000035a7e70 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x35a7e70)
#16 0x0000000003ea38eb (anonymous namespace)::EmitAssemblyHelper::RunOptimizationPipeline(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>&, std::unique_ptr<llvm::ToolOutputFile, std::default_delete<llvm::ToolOutputFile>>&, clang::BackendConsumer*) BackendUtil.cpp:0:0
#17 0x0000000003ea7115 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3ea7115)
#18 0x00000000045721de clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x45721de)
#19 0x0000000006718dac clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6718dac)
#20 0x00000000045725c8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x45725c8)
#21 0x000000000482d559 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x482d559)
#22 0x00000000047ac7ce clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x47ac7ce)
#23 0x000000000491335e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x491335e)
#24 0x0000000000ce9aff cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xce9aff)
#25 0x0000000000ce17ba ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#26 0x00000000045b57c9 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
#27 0x0000000003b41e74 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3b41e74)
#28 0x00000000045b5dbf 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
#29 0x000000000457c0ad clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x457c0ad)
#30 0x000000000457d19d 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+++0x457d19d)
#31 0x0000000004584555 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4584555)
#32 0x0000000000ce6999 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xce6999)
#33 0x0000000000bb3494 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xbb3494)
#34 0x00007cb33e829d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#35 0x00007cb33e829e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#36 0x0000000000ce126e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xce126e)
clang++: error: clang frontend command failed with exit code 139 (use -v to see invocation)
Compiler returned: 139
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzkWl9z27ay_zT0C0YaEiQl6sEPsmzftE0nnsjtnbkvGhBcymgggAVARc7D_exnAJASQcuJk2N32nM8bUzj729_u9hd_CFas60AuIzyqyi_viCteZDq8pH9QURWZPlFKavHywgvI7y8f2AaGdCGEg2IabQFAYoYqFD5iAiq2y9fQE194yi-juLu35XcNYyDQjeHhksFKkqXKMqvHoxpdJQuI3wb4dutrErJzVSqbYRvv0T4tpBl9ucf_5vNo_w6wsXLm-PFcHqHe084qxCVFaDPjHNEFdEPSApEORFbRLQGZZgUyKhWfLKz-BFmsf-PNo0voZxojdbR_Mr_3bQlZ_TYAaH_X0e4iPACbTbEGMXK1sBm48oKIRWYVgmLEC-i9KrvtJesQrXveCyO5tfHbzgYUAKVUnJEH4B-inBBpdAGrSM8G_ZiwjgtRbhwrfeEt2DxHCEjxGpk-3fjdID9IOhMadgZIS8ESgYCWKzdZ1cbB3KEbA7V85NBGmCnkXkgBhmrrK0EjUpCPyEjvYIm6bSYDnutja2u2l3zVFfduEIb1VKnVAU1KBCUiS1ig3IhDYJdCVUFFWICEVQSzSgqubQcJEfpcK6gnppdk6AovUaEc0mJLXbmMF1HeIUIZ1tLyqkPJZy79kzs5SdAQraighp9ASXhYBCpKqUbQ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