Issue 120088
Summary clang crash on x86_64-linux-gnu: error in backend: Broken module found, compilation aborted!
Labels
Assignees
Reporter bi6c
    Compiler Explorer: https://godbolt.org/z/zMP936sGe
```console
<source>:55:5: warning: function 'async_mutual_loop2' declared 'noreturn' should not return [-Winvalid-noreturn]
   55 |     return async_leaf1(ctx);
      | ^
<source>:57:5: warning: function 'async_mutual_loop2' declared 'noreturn' should not return [-Winvalid-noreturn]
   57 |     return async_leaf2(ctx);
      |     ^
<source>:59:3: warning: function 'async_mutual_loop2' declared 'noreturn' should not return [-Winvalid-noreturn]
   59 |   return async_mutual_loop1(u - 2, ctx);
 |   ^
<source>:69:22: warning: unknown attribute 'noipa' ignored [-Wunknown-attributes]
   69 | char __attribute__ ((noipa)) c_calling_async(MYBOOL b, unsigned u) {
      | ^~~~~
musttail call must precede a ret with an optional bitcast
  musttail call swifttailcc void @async_mutual_loop2(i32 noundef %sub, ptr noundef swiftasync %7) #2, !dbg !105
fatal error: error in backend: Broken module found, compilation aborted!
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 -fno-verbose-asm -c --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 0x0000000003c56df8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3c56df8)
 #1 0x0000000003c54b04 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3c54b04)
 #2 0x0000000003ba25d6 llvm::CrashRecoveryContext::HandleExit(int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3ba25d6)
 #3 0x0000000003c4be2e llvm::sys::Process::Exit(int, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3c4be2e)
 #4 0x0000000000cdf720 LLVMErrorHandler(void*, char const*, bool) cc1_main.cpp:0:0
 #5 0x0000000003bad683 llvm::report_fatal_error(llvm::Twine const&, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3bad683)
 #6 0x0000000003bad7e8 (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3bad7e8)
 #7 0x0000000003636bb8 (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3636bb8)
 #8 0x0000000003ef736e 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+0x3ef736e)
 #9 0x00000000036018c0 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x36018c0)
#10 0x0000000003f0a1ef (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
#11 0x0000000003f0dd65 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+0x3f0dd65)
#12 0x00000000045e028e clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x45e028e)
#13 0x00000000065ca42c clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x65ca42c)
#14 0x00000000045e0668 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x45e0668)
#15 0x0000000004899a89 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4899a89)
#16 0x000000000481c48e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x481c48e)
#17 0x00000000049862ce clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x49862ce)
#18 0x0000000000ce1c7f cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xce1c7f)
#19 0x0000000000cd971a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#20 0x0000000004624ad9 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
#21 0x0000000003ba2514 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3ba2514)
#22 0x00000000046250cf 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
#23 0x00000000045ea3dd clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x45ea3dd)
#24 0x00000000045eb4cd 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+0x45eb4cd)
#25 0x00000000045f2a45 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x45f2a45)
#26 0x0000000000cdeac3 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xcdeac3)
#27 0x0000000000bac364 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xbac364)
#28 0x000071129a429d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#29 0x000071129a429e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#30 0x0000000000cd91c5 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xcd91c5)
clang: error: clang frontend command failed with exit code 70 (use -v to see invocation)
Compiler returned: 70
```
Code:
```c

#define SWIFTCALL __attribute__((swiftcall))
#define SWIFTASYNCCALL __attribute__((swiftasynccall))
#define ASYNC_CONTEXT __attribute__((swift_async_context))

SWIFTASYNCCALL void async_leaf1(char * ASYNC_CONTEXT ctx) {
  *ctx += 1;
}

SWIFTASYNCCALL void async_leaf2(char * ASYNC_CONTEXT ctx) {
  *ctx += 2;
}

#if __cplusplus
 #define MYBOOL bool
#else
  #define MYBOOL _Bool
#endif

SWIFTASYNCCALL void async_branch(MYBOOL b, char * ASYNC_CONTEXT ctx) {
  if (b) {
 return async_leaf1(ctx);
  } else {
    return async_leaf2(ctx);
 }
}

SWIFTASYNCCALL void async_not_all_tail(char * ASYNC_CONTEXT ctx) {
 async_leaf1(ctx);
  return async_leaf2(ctx);
}

SWIFTASYNCCALL void async_loop(unsigned u, char * ASYNC_CONTEXT ctx) {
  if (u == 0) {
 return async_leaf1(ctx);
  } else if (u == 1) {
    return async_leaf2(ctx);
  }
  return async_loop(u - 2, ctx);
}

SWIFTASYNCCALL void async_mutual_loop2(unsigned u, char * ASYNC_CONTEXT ctx) __attribute__((noreturn));

SWIFTASYNCCALL void async_mutual_loop1(unsigned u, char * ASYNC_CONTEXT ctx) {
  if (u == 0) {
    return async_leaf1(ctx);
  } else if (u == 1) {
    return async_leaf2(ctx);
 }
  return async_mutual_loop2(u - 2, ctx);
}

SWIFTASYNCCALL void async_mutual_loop2(unsigned u, char * ASYNC_CONTEXT ctx) {
  if (u == 0) {
 return async_leaf1(ctx);
  } else if (u == 1) {
    return async_leaf2(ctx);
  }
  return async_mutual_loop1(u - 2, ctx);
}

SWIFTCALL char sync_calling_async(MYBOOL b, unsigned u) {
  char x = 'a';
  async_branch(b, &x);
  async_loop(u, &x);
  return x;
}

char __attribute__ ((noipa)) c_calling_async(MYBOOL b, unsigned u) {
  char x = 'a';
  async_branch(b, &x);
  async_loop(u, &x);
  return x;
}

#if __cplusplus
struct S {
  SWIFTASYNCCALL void (*fptr)(char * ASYNC_CONTEXT);

  SWIFTASYNCCALL void async_leaf_method(char * ASYNC_CONTEXT ctx) {
    *ctx += 1;
  }
  SWIFTASYNCCALL void async_nonleaf_method1(char * ASYNC_CONTEXT ctx) {
    return async_leaf_method(ctx);
  }
  SWIFTASYNCCALL void async_nonleaf_method2(char * ASYNC_CONTEXT ctx) {
    return this->async_leaf_method(ctx);
  }
};

SWIFTASYNCCALL void (S::*async_leaf_method_ptr)(char * ASYNC_CONTEXT) = &S::async_leaf_method;

SWIFTASYNCCALL void async_struct_field_and_methods(int i, S &sref, S *sptr) {
  char x = 'a';
 if (i == 0) {
    return (*sref.fptr)(&x);
  } else if (i == 1) {
 return sref.async_nonleaf_method1(&x);
  } else if (i == 2) {
    return (*(sptr->fptr))(&x);
  } else if (i == 3) {
    return sptr->async_nonleaf_method2(&x);
  } else if (i == 4) {
    return (sref.*async_leaf_method_ptr)(&x);
  }
  return (sptr->*async_leaf_method_ptr)(&x);
}

#endif
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to