Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clang crashes when compiling coroutine on Windows #109253

Open
flode opened this issue Sep 19, 2024 · 6 comments
Open

clang crashes when compiling coroutine on Windows #109253

flode opened this issue Sep 19, 2024 · 6 comments
Assignees
Labels
confirmed Verified by a second party coroutines C++20 coroutines crash-on-valid llvm:optimizations needs-reduction Large reproducer that should be reduced into a simpler form platform:windows regression:19 Regression in 19 release

Comments

@flode
Copy link

flode commented Sep 19, 2024

We observed a crash on Windows in coroutine code after upgrading to 19.1. Needs at least /O1.

Compiling the attached repro code, crashes.

Clang-cl 19.1
msvc-14.39.33519
windows sdk 10.0.22621.0

Stack dump:
0.      Program arguments: external\\clang_windows\\bin\\clang-cl.exe /O1 /c clangcl19windowscoroutinecrash.cpp /EHsc msvc /imsvc external/msvc/include /imsvc external/windows_sdk/Include/shared/ /imsvc external/windows_sdk/Include/ucrt/ /imsvc external/windows_sdk/Include/um/ -Xclang -std=c++23
1.      <eof> parser at end of file
2.      Optimizer
3.      Running pass "require<globals-aa>,function(invalidate<aa>),require<profile-summary>,cgscc(devirt<4>(inline,function-attrs<skip-non-recursive-function-attrs>,function<eager-inv;no-rerun>(sroa<modify-cfg>,early-cse<memssa>,speculative-execution<only-if-divergent-target>,jump-threading,correlated-propagation,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,instcombine<max-iterations=1;no-use-loop-info;no-verify-fixpoint>,aggressive-instcombine,tailcallelim,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,reassociate,constraint-elimination,loop-mssa(loop-instsimplify,loop-simplifycfg,licm<no-allowspeculation>,loop-rotate<header-duplication;no-prepare-for-lto>,licm<allowspeculation>,simple-loop-unswitch<no-nontrivial;trivial>),simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,instcombine<max-iterations=1;no-use-loop-info;no-verify-fixpoint>,loop(loop-idiom,indvars,simple-loop-unswitch<no-nontrivial;trivial>,loop-deletion,loop-unroll-full),sroa<modify-cfg>,vector-combine,mldst-motion<no-split-footer-bb>,gvn<>,sccp,bdce,instcombine<max-iterations=1;no-use-loop-info;no-verify-fixpoint>,jump-threading,correlated-propagation,adce,memcpyopt,dse,move-auto-init,loop-mssa(licm<allowspeculation>),coro-elide,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;hoist-common-insts;sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,instcombine<max-iterations=1;no-use-loop-info;no-verify-fixpoint>),function-attrs,function(require<should-not-run-function-passes>),coro-split)),function(invalidate<should-not-run-function-passes>),cgscc(devirt<4>())" on module "C:\Users\fscheibner\hyper-db\clangcrashminimal.cpp"
4.      Running pass "cgscc(devirt<4>(inline,function-attrs<skip-non-recursive-function-attrs>,function<eager-inv;no-rerun>(sroa<modify-cfg>,early-cse<memssa>,speculative-execution<only-if-divergent-target>,jump-threading,correlated-propagation,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,instcombine<max-iterations=1;no-use-loop-info;no-verify-fixpoint>,aggressive-instcombine,tailcallelim,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,reassociate,constraint-elimination,loop-mssa(loop-instsimplify,loop-simplifycfg,licm<no-allowspeculation>,loop-rotate<header-duplication;no-prepare-for-lto>,licm<allowspeculation>,simple-loop-unswitch<no-nontrivial;trivial>),simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,instcombine<max-iterations=1;no-use-loop-info;no-verify-fixpoint>,loop(loop-idiom,indvars,simple-loop-unswitch<no-nontrivial;trivial>,loop-deletion,loop-unroll-full),sroa<modify-cfg>,vector-combine,mldst-motion<no-split-footer-bb>,gvn<>,sccp,bdce,instcombine<max-iterations=1;no-use-loop-info;no-verify-fixpoint>,jump-threading,correlated-propagation,adce,memcpyopt,dse,move-auto-init,loop-mssa(licm<allowspeculation>),coro-elide,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;hoist-common-insts;sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,instcombine<max-iterations=1;no-use-loop-info;no-verify-fixpoint>),function-attrs,function(require<should-not-run-function-passes>),coro-split))" on module "clangcl19windowscoroutinecrashl.cpp"
5.      Running pass "jump-threading" on function "?asyncInit@@YA?AU?$AsyncFunction@H@@XZ.resume"
Exception Code: 0xC0000005

clang-cl: error: clang frontend command failed due to signal (use -v to see invocation)
hyper.salesforce.com clang version 19.1.0
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: external\clang_windows\bin
clang-cl: note: diagnostic msg:
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang-cl: note: diagnostic msg: AppData\Local\Temp\2\clangcl19windowscoroutinecrash-c2ab57.cpp
clang-cl: note: diagnostic msg: AppData\Local\Temp\2\clangcl19windowscoroutinecrash-c2ab57.sh
clang-cl: note: diagnostic msg:

********************

clangcl19windowscoroutinecrash.zip

@dtcxzyw dtcxzyw added llvm:optimizations crash-on-valid needs-reduction Large reproducer that should be reduced into a simpler form and removed new issue labels Sep 19, 2024
@vogelsgesang
Copy link
Member

Note that this is a regression between 17.0.6 and 19.1.0 (we skipped the 18 release, and hence don't know if it also reproduces there)

@vogelsgesang vogelsgesang added the regression:19 Regression in 19 release label Sep 19, 2024
@Endilll
Copy link
Contributor

Endilll commented Oct 3, 2024

Confirmed on Clang 20.0 (trunk): https://godbolt.org/z/YxKseEGzv
Reduced by C-Reduce:

namespace std {
template <class _Ret>
struct coroutine_traits : _Ret {};

template <class = void>
struct coroutine_handle {
  static coroutine_handle from_address(void *);
  operator coroutine_handle<>();
};

struct suspend_always {
  int await_ready();
  void await_suspend(coroutine_handle<>);
  void await_resume();
};

struct ostream;

template <class _Ty2>
struct _Compressed_pair {
  _Ty2 _Myval2;
};

struct default_delete {
  void operator()(int *_Ptr) {
    delete _Ptr;
  }
};

struct _Get_deleter_pointer_type {
  using type = int *;
};

struct unique_ptr {
  using pointer = _Get_deleter_pointer_type::type;
  
  ~unique_ptr() {
    default_delete __trans_tmp_1;
    __trans_tmp_1(_Mypair._Myval2);
  }

  _Compressed_pair<pointer> _Mypair;
};

template <class>
unique_ptr make_unique();

template <class _Traits>
void operator<<(_Traits &, int);

extern ostream cerr;
} // namespace std

using namespace std;

struct AsyncFunctionPromise {
  auto initial_suspend() {
    return suspend_always();
  }

  struct FinalAwaitable {
    int await_ready() noexcept;
    void await_resume() noexcept;
    
    template <typename Promise>
    void await_suspend(Promise) noexcept;
  };

  auto final_suspend() noexcept {
    return FinalAwaitable();
  }

  auto get_return_object() {
    return coroutine_handle<AsyncFunctionPromise>();
  }

  void return_value(int);
  void unhandled_exception();
};

struct AsyncFunction {
  using promise_type = AsyncFunctionPromise;
  using Handle = coroutine_handle<promise_type>;
  AsyncFunction(Handle);
};

AsyncFunction asyncInit() {
  try {
    unique_ptr mem;
    try {
      mem = make_unique<int>();
    } catch (int) {
    }
    cerr << 0;
  } catch (int) {
  }
  co_return 0;
}

Clang 20.0 crash:

Instruction does not dominate all uses!
  %mem.sroa.0.0 = phi ptr [ %.try.cont1368, %"try.cont13.from.??1unique_ptr@std@@QEAA@XZ.exit" ], [ %.try.cont13, %try.cont13.from.catch11 ]
  %mem.sroa.0.0.ehcleanup15 = phi ptr [ %mem.sroa.0.0, %ehcleanup15.corodispatch ]
fatal error: error in backend: Broken function

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 -std=c++20 -O1 -target x86_64-pc-windows-msvc19.33.0 <source>
1.	<eof> parser at end of file
2.	Optimizer
3.	Running pass "require<globals-aa>,function(invalidate<aa>),require<profile-summary>,cgscc(devirt<4>(inline,function-attrs<skip-non-recursive-function-attrs>,function<eager-inv;no-rerun>(sroa<modify-cfg>,early-cse<memssa>,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;no-sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,instcombine<max-iterations=1;no-verify-fixpoint>,libcalls-shrinkwrap,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;no-sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,reassociate,loop-mssa(loop-instsimplify,loop-simplifycfg,licm<no-allowspeculation>,loop-rotate<header-duplication;no-prepare-for-lto>,licm<allowspeculation>,simple-loop-unswitch<no-nontrivial;trivial>),simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;no-sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,instcombine<max-iterations=1;no-verify-fixpoint>,loop(loop-idiom,indvars,loop-deletion,loop-unroll-full),sroa<modify-cfg>,memcpyopt,sccp,bdce,instcombine<max-iterations=1;no-verify-fixpoint>,coro-elide,adce,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;no-sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,instcombine<max-iterations=1;no-verify-fixpoint>),function-attrs,function(require<should-not-run-function-passes>),coro-split,function(coro-annotation-elide))),function(invalidate<should-not-run-function-passes>),cgscc(devirt<4>())" on module "<source>"
4.	Running pass "cgscc(devirt<4>(inline,function-attrs<skip-non-recursive-function-attrs>,function<eager-inv;no-rerun>(sroa<modify-cfg>,early-cse<memssa>,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;no-sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,instcombine<max-iterations=1;no-verify-fixpoint>,libcalls-shrinkwrap,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;no-sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,reassociate,loop-mssa(loop-instsimplify,loop-simplifycfg,licm<no-allowspeculation>,loop-rotate<header-duplication;no-prepare-for-lto>,licm<allowspeculation>,simple-loop-unswitch<no-nontrivial;trivial>),simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;no-sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,instcombine<max-iterations=1;no-verify-fixpoint>,loop(loop-idiom,indvars,loop-deletion,loop-unroll-full),sroa<modify-cfg>,memcpyopt,sccp,bdce,instcombine<max-iterations=1;no-verify-fixpoint>,coro-elide,adce,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;no-sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,instcombine<max-iterations=1;no-verify-fixpoint>),function-attrs,function(require<should-not-run-function-passes>),coro-split,function(coro-annotation-elide)))" on module "<source>"
5.	While splitting coroutine @"?asyncInit@@YA?AUAsyncFunction@@XZ"
 #0 0x0000000003b97db8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3b97db8)
 #1 0x0000000003b95a7c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3b95a7c)
 #2 0x0000000003ae4706 llvm::CrashRecoveryContext::HandleExit(int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3ae4706)
 #3 0x0000000003b8cd9e llvm::sys::Process::Exit(int, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3b8cd9e)
 #4 0x0000000000cd6610 LLVMErrorHandler(void*, char const*, bool) cc1_main.cpp:0:0
 #5 0x0000000003aef723 llvm::report_fatal_error(llvm::Twine const&, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3aef723)
 #6 0x0000000003aef888 (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3aef888)
 #7 0x00000000052fca94 (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x52fca94)
 #8 0x000000000530c620 llvm::CoroSplitPass::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x530c620)
 #9 0x00000000051b5ece llvm::detail::PassModel<llvm::LazyCallGraph::SCC, llvm::CoroSplitPass, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x51b5ece)
#10 0x0000000002a52362 llvm::PassManager<llvm::LazyCallGraph::SCC, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x2a52362)
#11 0x00000000051b4e0e llvm::detail::PassModel<llvm::LazyCallGraph::SCC, llvm::PassManager<llvm::LazyCallGraph::SCC, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x51b4e0e)
#12 0x0000000002a57c76 llvm::DevirtSCCRepeatedPass::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x2a57c76)
#13 0x00000000051b4e2e llvm::detail::PassModel<llvm::LazyCallGraph::SCC, llvm::DevirtSCCRepeatedPass, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x51b4e2e)
#14 0x0000000002a55a06 llvm::ModuleToPostOrderCGSCCPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x2a55a06)
#15 0x00000000051b4dee llvm::detail::PassModel<llvm::Module, llvm::ModuleToPostOrderCGSCCPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x51b4dee)
#16 0x000000000354ed80 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x354ed80)
#17 0x00000000053b6775 llvm::ModuleInlinerWrapperPass::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x53b6775)
#18 0x00000000050531ee llvm::detail::PassModel<llvm::Module, llvm::ModuleInlinerWrapperPass, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x50531ee)
#19 0x000000000354ed80 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x354ed80)
#20 0x0000000003e4111b (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
#21 0x0000000003e446dd 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+++0x3e446dd)
#22 0x00000000044ee28e clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x44ee28e)
#23 0x000000000661746c clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x661746c)
#24 0x00000000044ee678 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x44ee678)
#25 0x00000000047a8169 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x47a8169)
#26 0x0000000004726e7e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4726e7e)
#27 0x000000000488dc0e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x488dc0e)
#28 0x0000000000cd8aff cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xcd8aff)
#29 0x0000000000cd080a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#30 0x00000000045328f9 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 0x0000000003ae4644 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3ae4644)
#32 0x0000000004532eef 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 0x00000000044f827d clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x44f827d)
#34 0x00000000044f936d 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+++0x44f936d)
#35 0x0000000004501025 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4501025)
#36 0x0000000000cd59cf clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xcd59cf)
#37 0x0000000000ba5414 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xba5414)
#38 0x00007b1eb9829d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#39 0x00007b1eb9829e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#40 0x0000000000cd02be _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xcd02be)
clang++: error: clang frontend command failed with exit code 70 (use -v to see invocation)
Compiler returned: 70

@Endilll
Copy link
Contributor

Endilll commented Oct 3, 2024

Well, the reduction above reproduces all the way to Clang 14, which appears to be the first supporting C++20 coroutines.

@Endilll Endilll added platform:windows confirmed Verified by a second party coroutines C++20 coroutines and removed regression labels Oct 3, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Oct 3, 2024

@llvm/issue-subscribers-coroutines

Author: Florian Scheibner (flode)

We observed a crash on Windows in coroutine code after upgrading to 19.1. Needs at least /O1.

Compiling the attached repro code, crashes.

Clang-cl 19.1
msvc-14.39.33519
windows sdk 10.0.22621.0

Stack dump:
0.      Program arguments: external\\clang_windows\\bin\\clang-cl.exe /O1 /c clangcl19windowscoroutinecrash.cpp /EHsc msvc /imsvc external/msvc/include /imsvc external/windows_sdk/Include/shared/ /imsvc external/windows_sdk/Include/ucrt/ /imsvc external/windows_sdk/Include/um/ -Xclang -std=c++23
1.      &lt;eof&gt; parser at end of file
2.      Optimizer
3.      Running pass "require&lt;globals-aa&gt;,function(invalidate&lt;aa&gt;),require&lt;profile-summary&gt;,cgscc(devirt&lt;4&gt;(inline,function-attrs&lt;skip-non-recursive-function-attrs&gt;,function&lt;eager-inv;no-rerun&gt;(sroa&lt;modify-cfg&gt;,early-cse&lt;memssa&gt;,speculative-execution&lt;only-if-divergent-target&gt;,jump-threading,correlated-propagation,simplifycfg&lt;bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables&gt;,instcombine&lt;max-iterations=1;no-use-loop-info;no-verify-fixpoint&gt;,aggressive-instcombine,tailcallelim,simplifycfg&lt;bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables&gt;,reassociate,constraint-elimination,loop-mssa(loop-instsimplify,loop-simplifycfg,licm&lt;no-allowspeculation&gt;,loop-rotate&lt;header-duplication;no-prepare-for-lto&gt;,licm&lt;allowspeculation&gt;,simple-loop-unswitch&lt;no-nontrivial;trivial&gt;),simplifycfg&lt;bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables&gt;,instcombine&lt;max-iterations=1;no-use-loop-info;no-verify-fixpoint&gt;,loop(loop-idiom,indvars,simple-loop-unswitch&lt;no-nontrivial;trivial&gt;,loop-deletion,loop-unroll-full),sroa&lt;modify-cfg&gt;,vector-combine,mldst-motion&lt;no-split-footer-bb&gt;,gvn&lt;&gt;,sccp,bdce,instcombine&lt;max-iterations=1;no-use-loop-info;no-verify-fixpoint&gt;,jump-threading,correlated-propagation,adce,memcpyopt,dse,move-auto-init,loop-mssa(licm&lt;allowspeculation&gt;),coro-elide,simplifycfg&lt;bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;hoist-common-insts;sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables&gt;,instcombine&lt;max-iterations=1;no-use-loop-info;no-verify-fixpoint&gt;),function-attrs,function(require&lt;should-not-run-function-passes&gt;),coro-split)),function(invalidate&lt;should-not-run-function-passes&gt;),cgscc(devirt&lt;4&gt;())" on module "C:\Users\fscheibner\hyper-db\clangcrashminimal.cpp"
4.      Running pass "cgscc(devirt&lt;4&gt;(inline,function-attrs&lt;skip-non-recursive-function-attrs&gt;,function&lt;eager-inv;no-rerun&gt;(sroa&lt;modify-cfg&gt;,early-cse&lt;memssa&gt;,speculative-execution&lt;only-if-divergent-target&gt;,jump-threading,correlated-propagation,simplifycfg&lt;bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables&gt;,instcombine&lt;max-iterations=1;no-use-loop-info;no-verify-fixpoint&gt;,aggressive-instcombine,tailcallelim,simplifycfg&lt;bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables&gt;,reassociate,constraint-elimination,loop-mssa(loop-instsimplify,loop-simplifycfg,licm&lt;no-allowspeculation&gt;,loop-rotate&lt;header-duplication;no-prepare-for-lto&gt;,licm&lt;allowspeculation&gt;,simple-loop-unswitch&lt;no-nontrivial;trivial&gt;),simplifycfg&lt;bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables&gt;,instcombine&lt;max-iterations=1;no-use-loop-info;no-verify-fixpoint&gt;,loop(loop-idiom,indvars,simple-loop-unswitch&lt;no-nontrivial;trivial&gt;,loop-deletion,loop-unroll-full),sroa&lt;modify-cfg&gt;,vector-combine,mldst-motion&lt;no-split-footer-bb&gt;,gvn&lt;&gt;,sccp,bdce,instcombine&lt;max-iterations=1;no-use-loop-info;no-verify-fixpoint&gt;,jump-threading,correlated-propagation,adce,memcpyopt,dse,move-auto-init,loop-mssa(licm&lt;allowspeculation&gt;),coro-elide,simplifycfg&lt;bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;hoist-common-insts;sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables&gt;,instcombine&lt;max-iterations=1;no-use-loop-info;no-verify-fixpoint&gt;),function-attrs,function(require&lt;should-not-run-function-passes&gt;),coro-split))" on module "clangcl19windowscoroutinecrashl.cpp"
5.      Running pass "jump-threading" on function "?asyncInit@@<!-- -->YA?AU?$AsyncFunction@<!-- -->H@@<!-- -->XZ.resume"
Exception Code: 0xC0000005

clang-cl: error: clang frontend command failed due to signal (use -v to see invocation)
hyper.salesforce.com clang version 19.1.0
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: external\clang_windows\bin
clang-cl: note: diagnostic msg:
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang-cl: note: diagnostic msg: AppData\Local\Temp\2\clangcl19windowscoroutinecrash-c2ab57.cpp
clang-cl: note: diagnostic msg: AppData\Local\Temp\2\clangcl19windowscoroutinecrash-c2ab57.sh
clang-cl: note: diagnostic msg:

********************

clangcl19windowscoroutinecrash.zip

@Endilll
Copy link
Contributor

Endilll commented Oct 3, 2024

Well, the original reproducer crashes Clang 17, too. I guess something has changed in MS STL's <coroutine> header in the meantime, that makes all versions of Clang crash.

@rnk
Copy link
Collaborator

rnk commented Oct 3, 2024

This looks like a bad interaction between C++ coroutines and C++ EH under the MSVC ABI. There are at least a few tests for this in the LLVM coroutine test suite, so there is some hope that this can be made to work without too much effort:

$ git grep -l cleanuppad llvm/test/Transforms/Coroutines/ | wc -l
10

@vogelsgesang vogelsgesang changed the title Clang-cl 19.1 crash on Windows clang crashes when compiling coroutine on Windows Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed Verified by a second party coroutines C++20 coroutines crash-on-valid llvm:optimizations needs-reduction Large reproducer that should be reduced into a simpler form platform:windows regression:19 Regression in 19 release
Projects
None yet
Development

No branches or pull requests

8 participants