llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.31k stars 11.69k forks source link

[Clang] Assertion `CurFn->isDeclaration() && "Function already has body?"' failed. #110774

Open yijan4845 opened 3 days ago

yijan4845 commented 3 days ago

Compiler Explorer: https://godbolt.org/z/vojqnYd6d

Attempting to compile the following program with Clang Assertion Trunk:

typedef unsigned long size_t;
#define AVAILABLE_EXTERNALLY extern inline __attribute__((always_inline)) __attribute__((gnu_inline))

AVAILABLE_EXTERNALLY int memcmp(const void *a, const void *b, size_t c) {
  return __builtin_memcmp(a, b, c);
}

int bar(const void *a, const void *b, size_t c) {
  return memcmp(a, b, c);
}

AVAILABLE_EXTERNALLY int memcmp(const void *a, const void *b, size_t c) {
  return __builtin_memcmp(a, b, c);
}

Stack dump:

clang: /root/llvm-project/clang/lib/CodeGen/CodeGenFunction.cpp:773: void clang::CodeGen::CodeGenFunction::StartFunction(clang::GlobalDecl, clang::QualType, llvm::Function*, const clang::CodeGen::CGFunctionInfo&, const clang::CodeGen::FunctionArgList&, clang::SourceLocation, clang::SourceLocation): Assertion `CurFn->isDeclaration() && "Function already has body?"' 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 -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -O3 <source>
1.  <eof> parser at end of file
2.  Per-file LLVM IR generation
3.  <source>:12:26: Generating code for declaration 'memcmp'
 #0 0x0000000003b93538 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3b93538)
 #1 0x0000000003b911fc llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3b911fc)
 #2 0x0000000003adf908 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007d1631042520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007d16310969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #5 0x00007d1631042476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #6 0x00007d16310287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #7 0x00007d163102871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #8 0x00007d1631039e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #9 0x0000000003f759f0 clang::CodeGen::CodeGenFunction::StartFunction(clang::GlobalDecl, clang::QualType, llvm::Function*, clang::CodeGen::CGFunctionInfo const&, clang::CodeGen::FunctionArgList const&, clang::SourceLocation, clang::SourceLocation) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3f759f0)
#10 0x0000000003f774f9 clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3f774f9)
#11 0x0000000003fdfeda clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3fdfeda)
#12 0x0000000003fdabb5 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3fdabb5)
#13 0x0000000003fe6b8d clang::CodeGen::CodeGenModule::EmitDeferred() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3fe6b8d)
#14 0x0000000003fe8ca3 clang::CodeGen::CodeGenModule::Release() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3fe8ca3)
#15 0x00000000044eaeee (anonymous namespace)::CodeGeneratorImpl::HandleTranslationUnit(clang::ASTContext&) ModuleBuilder.cpp:0:0
#16 0x00000000044e8b45 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x44e8b45)
#17 0x000000000660d50c clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x660d50c)
#18 0x00000000044e92f8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x44e92f8)
#19 0x00000000047a2c89 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x47a2c89)
#20 0x000000000472199e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x472199e)
#21 0x00000000048887ae clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x48887ae)
#22 0x0000000000cd779f cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xcd779f)
#23 0x0000000000ccf4aa ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#24 0x000000000452d579 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
#25 0x0000000003adfdb4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3adfdb4)
#26 0x000000000452db6f 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
#27 0x00000000044f2efd clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x44f2efd)
#28 0x00000000044f3fed 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+0x44f3fed)
#29 0x00000000044fbca5 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x44fbca5)
#30 0x0000000000cd466f clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xcd466f)
#31 0x0000000000ba3b84 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xba3b84)
#32 0x00007d1631029d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#33 0x00007d1631029e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#34 0x0000000000ccef5e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xccef5e)
clang: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134
llvmbot commented 3 days ago

@llvm/issue-subscribers-clang-codegen

Author: Yihan Yang (yijan4845)

Compiler Explorer: [https://godbolt.org/z/vojqnYd6d](https://godbolt.org/z/vojqnYd6d) Attempting to compile the following program with Clang Assertion Trunk: ```c typedef unsigned long size_t; #define AVAILABLE_EXTERNALLY extern inline __attribute__((always_inline)) __attribute__((gnu_inline)) AVAILABLE_EXTERNALLY int memcmp(const void *a, const void *b, size_t c) { return __builtin_memcmp(a, b, c); } int bar(const void *a, const void *b, size_t c) { return memcmp(a, b, c); } AVAILABLE_EXTERNALLY int memcmp(const void *a, const void *b, size_t c) { return __builtin_memcmp(a, b, c); } ``` Stack dump: ``` clang: /root/llvm-project/clang/lib/CodeGen/CodeGenFunction.cpp:773: void clang::CodeGen::CodeGenFunction::StartFunction(clang::GlobalDecl, clang::QualType, llvm::Function*, const clang::CodeGen::CGFunctionInfo&, const clang::CodeGen::FunctionArgList&, clang::SourceLocation, clang::SourceLocation): Assertion `CurFn->isDeclaration() && "Function already has body?"' 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 -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -O3 <source> 1. <eof> parser at end of file 2. Per-file LLVM IR generation 3. <source>:12:26: Generating code for declaration 'memcmp' #0 0x0000000003b93538 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3b93538) #1 0x0000000003b911fc llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3b911fc) #2 0x0000000003adf908 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0 #3 0x00007d1631042520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520) #4 0x00007d16310969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc) #5 0x00007d1631042476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476) #6 0x00007d16310287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3) #7 0x00007d163102871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b) #8 0x00007d1631039e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96) #9 0x0000000003f759f0 clang::CodeGen::CodeGenFunction::StartFunction(clang::GlobalDecl, clang::QualType, llvm::Function*, clang::CodeGen::CGFunctionInfo const&, clang::CodeGen::FunctionArgList const&, clang::SourceLocation, clang::SourceLocation) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3f759f0) #10 0x0000000003f774f9 clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3f774f9) #11 0x0000000003fdfeda clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3fdfeda) #12 0x0000000003fdabb5 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3fdabb5) #13 0x0000000003fe6b8d clang::CodeGen::CodeGenModule::EmitDeferred() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3fe6b8d) #14 0x0000000003fe8ca3 clang::CodeGen::CodeGenModule::Release() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3fe8ca3) #15 0x00000000044eaeee (anonymous namespace)::CodeGeneratorImpl::HandleTranslationUnit(clang::ASTContext&) ModuleBuilder.cpp:0:0 #16 0x00000000044e8b45 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x44e8b45) #17 0x000000000660d50c clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x660d50c) #18 0x00000000044e92f8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x44e92f8) #19 0x00000000047a2c89 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x47a2c89) #20 0x000000000472199e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x472199e) #21 0x00000000048887ae clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x48887ae) #22 0x0000000000cd779f cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xcd779f) #23 0x0000000000ccf4aa ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0 #24 0x000000000452d579 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 #25 0x0000000003adfdb4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3adfdb4) #26 0x000000000452db6f 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 #27 0x00000000044f2efd clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x44f2efd) #28 0x00000000044f3fed 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+0x44f3fed) #29 0x00000000044fbca5 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x44fbca5) #30 0x0000000000cd466f clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xcd466f) #31 0x0000000000ba3b84 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xba3b84) #32 0x00007d1631029d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90) #33 0x00007d1631029e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40) #34 0x0000000000ccef5e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xccef5e) clang: error: clang frontend command failed with exit code 134 (use -v to see invocation) Compiler returned: 134 ```
shafik commented 2 days ago

Looks like this started in clang-14: https://godbolt.org/z/KnaP8x8r4