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

    <tr>
        <th>Summary</th>
        <td>
            Clang++ with -O3 failed: Assertion `Ptr != End && "dereferencing end() iterator"' failed
        </td>
    </tr>

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

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

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

<pre>
    Godbolt repro: https://godbolt.org/z/odhqb3bxc

Run clang++ with -O3 on the following test:
[Test.cpp.zip](https://github.com/llvm/llvm-project/files/10673558/Test.cpp.zip)

```console
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-snapshot -fcolor-diagnostics -fno-crash-diagnostics -O3 <source>
1.      <eof> parser at end of file
2.      Optimizer
 #0 0x000055d22dc4572f llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x40bf72f)
 #1 0x000055d22dc436cc llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x40bd6cc)
 #2 0x000055d22db904c8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007f8b441de420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #4 0x00007f8b43cab00b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
 #5 0x00007f8b43c8a859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
 #6 0x00007f8b43c8a729 (/lib/x86_64-linux-gnu/libc.so.6+0x22729)
 #7 0x00007f8b43c9bfd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
 #8 0x000055d22deeb551 (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4365551)
 #9 0x000055d22df55338 (anonymous namespace)::HorizontalReduction::tryToReduce(llvm::slpvectorizer::BoUpSLP&, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo const&) SLPVectorizer.cpp:0:0
#10 0x000055d22df57904 llvm::SLPVectorizerPass::vectorizeHorReduction(llvm::PHINode*, llvm::Value*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::TargetTransformInfo*, llvm::SmallVectorImpl<llvm::WeakTrackingVH>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x43d1904)
#11 0x000055d22df5b9c6 llvm::SLPVectorizerPass::vectorizeRootInstruction(llvm::PHINode*, llvm::Value*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::TargetTransformInfo*) (.constprop.0) SLPVectorizer.cpp:0:0
#12 0x000055d22df5ee1a llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x43d8e1a)
#13 0x000055d22df61fa7 llvm::SLPVectorizerPass::runImpl(llvm::Function&, llvm::ScalarEvolution*, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo*, llvm::AAResults*, llvm::LoopInfo*, llvm::DominatorTree*, llvm::AssumptionCache*, llvm::DemandedBits*, llvm::OptimizationRemarkEmitter*) (.part.0) SLPVectorizer.cpp:0:0
#14 0x000055d22df62d9c llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x43dcd9c)
#15 0x000055d22f1a86b6 llvm::detail::PassModel<llvm::Function, llvm::SLPVectorizerPass, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x56226b6)
#16 0x000055d22b470b34 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x18eab34)
#17 0x000055d22d4c65bf llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x39405bf)
#18 0x000055d22b457066 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x18d1066)
#19 0x000055d22d4c473a llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x393e73a)
#20 0x000055d22e03afe0 (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>>&) BackendUtil.cpp:0:0
#21 0x000055d22e03dd51 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>>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x44b7d51)
#22 0x000055d22efc602c clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x544002c)
#23 0x000055d2302edd65 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6767d65)
#24 0x000055d22efc4b08 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x543eb08)
#25 0x000055d22e82e999 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4ca8999)
#26 0x000055d22e7b410e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4c2e10e)
#27 0x000055d22e916023 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4d90023)
#28 0x000055d22b0dba6d cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x1555a6d)
#29 0x000055d22b0d7b57 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#30 0x000055d22e6199d9 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
#31 0x000055d22db909b0 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x400a9b0)
#32 0x000055d22e61a28f 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
#33 0x000055d22e5e27ec clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4a5c7ec)
#34 0x000055d22e5e326d 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+++0x4a5d26d)
#35 0x000055d22e5ec43c clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4a6643c)
#36 0x000055d22b0da1a2 clang_main(int, char**) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x15541a2)
#37 0x00007f8b43c8c083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#38 0x000055d22b0d283e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x154c83e)
clang-17: 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/eJzsWttz46iz_muUF8ophO4PeXCc8c5szZ5JJdk9jy4ELZsTDFpAucxffwrJF2E7M8lWsrW_S9XsJhHQ9Pf1R9MgUWvFUgFcRNlllF2d0c6ttLm4o-6ZKnqlu9rZs1rz54tfNK-1dMhAa3SUTNHKudZGyTQi84jMl0PzuTbLiMy_R2Su-erPOqmfWISvIjwd_n_TKcQkVcuIXEbkEj0Kt0KTbwnSCrkVoEZLqR-FWiIH1nnrw-Ds8g6sO2dte_5dtFF2FZHywAHhVl19zvQ6InMpH7Y_Jq3R_wfMRWTeCAk2IvMY50WSZWVE5oFVUo1djXI8_GNaWS1heHrrKLtHvFu3O-fweYSra6OXhq4RNctuDcp5x5BnofUzM71uhQQzgadWagPGP_M0TKi1YJzQyk6c6dR9ROa1UNvmDUuTJX-kppmkaLJEE-3t0rb11jvXdu7cosktmkyWjE2c1pKtqFBRcvXD6X1nq2hrV9qhScO01GbCBV0qbZ1gFk0apSfMULsKH39LUJTMrO4Mgyj5NHAQew6iZAa6iZJPqKXGgkHUIVAc6QZ56oeexPf81jqxFt_BDM9QRB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