<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/110774>110774</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[Clang] Assertion `CurFn->isDeclaration() && "Function already has body?"' failed.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
yijan4845
</td>
</tr>
</table>
<pre>
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
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzkWltz4ygW_jXkhZJLQrIuD3lQHLu3pzI7vZ1s186TCiFkM41ACyhtz6_fAskXHCfdmfVsTdV2dRIbnct3Po4ORyCsNVsLSm_B_A7M72_wYDZS3e7Yb1gkeTK_qWWzu13IrmecKrjc9lwqqkBcQjC_2xjTaxCXAK0AWq1lU0tuZlKtAVr9DtDqWf72b_FrkzZgfg9Q_uPiqADhPQjL8XdpDO16w8QaGgnJCAaaDYWt5Fx-sxd6JdcKd_A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