llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

Crash when compiling template specialization with auto return type

Open llvmbot opened this issue 6 years ago • 6 comments

Bugzilla Link 40790
Version trunk
OS Linux
Reporter LLVM Bugzilla Contributor
CC @DougGregor,@zygoloid

Extended Description

At least the version 5.0 and all version upwards are affected.

Here is a small test case example:

template <typename T> T foo(int payload);

struct Bar { };

template <> auto foo(int payload) { Bar result; return result; }

Yes, this code has an error but the compiler should emit an error message instead of crashing.

llvmbot avatar Feb 20 '19 16:02 llvmbot

template <typename T>
T foo(int payload);

struct Bar
{ };

template <>
auto foo(int payload)
{
    Bar result;
    return result;
}

This reproduces on trunk (bef4007a421a35399dbdb5719299a6a9e6099bde)

https://godbolt.org/z/eYf8fMz7v

wheatman avatar Jun 27 '23 01:06 wheatman

If a bug still crashes on trunk then please include the assertion (if there is one) and the backtrace, example here: https://github.com/llvm/llvm-project/issues/63412#issuecomment-1601307972

This allows us to find duplicates and related bugs, otherwise it would be much more difficult.

shafik avatar Jun 27 '23 01:06 shafik

The backtrace was in the link, doesn't look to trigger an assertion

I'll copy it here

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-trunk/bin/clang++ -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics <source>
1.	<eof> parser at end of file
2.	<source>:8:6: LLVM IR generation of declaration 'foo'
3.	<source>:8:6: Generating code for declaration 'foo'
 #0 0x000055844e18a16f llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x362e16f)
 #1 0x000055844e18819c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x362c19c)
 #2 0x000055844e0d7e58 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007f8d18c4b420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #4 0x000055844e42c68a clang::CodeGen::CGDebugInfo::getOrCreateType(clang::QualType, llvm::DIFile*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x38d068a)
 #5 0x000055844e43138e clang::CodeGen::CGDebugInfo::CollectTemplateParams(std::optional<clang::CodeGen::CGDebugInfo::TemplateArgs>, llvm::DIFile*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x38d538e)
 #6 0x000055844e442a04 clang::CodeGen::CGDebugInfo::collectFunctionDeclProps(clang::GlobalDecl, llvm::DIFile*, llvm::StringRef&, llvm::StringRef&, llvm::DIScope*&, llvm::MDTupleTypedArrayWrapper<llvm::DINode>&, llvm::DINode::DIFlags&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x38e6a04)
 #7 0x000055844e443396 clang::CodeGen::CGDebugInfo::emitFunctionStart(clang::GlobalDecl, clang::SourceLocation, clang::SourceLocation, clang::QualType, llvm::Function*, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x38e7396)
 #8 0x000055844e4f904b 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-trunk/bin/clang+++0x399d04b)
 #9 0x000055844e4fcae6 clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x39a0ae6)
#10 0x000055844e555d8a clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x39f9d8a)
#11 0x000055844e552095 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x39f6095)
#12 0x000055844e552a00 clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x39f6a00)
#13 0x000055844e55a3c7 clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (.part.0) CodeGenModule.cpp:0:0
#14 0x000055844f325cfe (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) ModuleBuilder.cpp:0:0
#15 0x000055844f3180bd clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x47bc0bd)
#16 0x00005584506df384 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5b83384)
#17 0x000055844f32320d clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x47c720d)
#18 0x000055844ebfed61 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x40a2d61)
#19 0x000055844eb84193 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4028193)
#20 0x000055844ecdfd03 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4183d03)
#21 0x000055844b9ff72c cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0xea372c)
#22 0x000055844b9fadef ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#23 0x000055844e9d790d 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
#24 0x000055844e0d82d7 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x357c2d7)
#25 0x000055844e9d7dac 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
#26 0x000055844e99ec9e clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3e42c9e)
#27 0x000055844e99f66d clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3e4366d)
#28 0x000055844e9a9d3c clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3e4dd3c)
#29 0x000055844b9fd2ef clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0xea12ef)
#30 0x000055844b8f97b5 main (/opt/compiler-explorer/clang-trunk/bin/clang+++0xd9d7b5)
#31 0x00007f8d186f9083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#32 0x000055844b9f70ce _start (/opt/compiler-explorer/clang-trunk/bin/clang+++0xe9b0ce)
clang++: error: clang frontend command failed with exit code 139 (use -v to see invocation)
Compiler returned: 139

wheatman avatar Jun 27 '23 01:06 wheatman

@llvm/issue-subscribers-clang-codegen

llvmbot avatar Jun 27 '23 03:06 llvmbot

The backtrace was in the link, doesn't look to trigger an assertion

My point was that adding the assertions allows us to find duplicate or related bugs and this is really invaluable. Folks may have done a lot of footwork in duplicates or related bugs or they may have a simpler reproducer etc

We also can't rely on links remaining valid over time. We have plenty of old bugs where links no longer work and we can't do anything because the information is lost.

shafik avatar Jun 27 '23 15:06 shafik

We have plenty of old bugs where links no longer work and we can't do anything because the information is lost.

It worth mentioning that Compiler Explorer is quite robust. I remember encountering a couple of links to it from around 10 years ago that naively tried to showcase trunk crashing. Given how much we rely on it, I don't see a practical way to prepare measures against it shutting down.

Otherwise I agree, we have numerous lost test cases, because preprocessed sources where uploaded to various services that either went down or deleted such old data.

Endilll avatar Jun 27 '23 16:06 Endilll