Skip to content

Segfault with template-template in function #795

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

Closed
anarthal opened this issue Jan 14, 2025 · 5 comments · Fixed by #800
Closed

Segfault with template-template in function #795

anarthal opened this issue Jan 14, 2025 · 5 comments · Fixed by #800

Comments

@anarthal
Copy link

Code:

namespace repro {

template <template <class...> class ListType>
constexpr void f(ListType<int>)
{
}

}  // namespace repro

int main() {}

Segfaults:

/usr/include/c++/14/bits/unique_ptr.h:447: typename std::add_lvalue_reference<_Tp>::type std::unique_ptr<_Tp, _Dp>::operator*() const [with _Tp = clang::mrdocs::TypeInfo; _Dp = std::default_delete<clang::mrdocs::TypeInfo>; typename std::add_lvalue_reference<_Tp>::type = clang::mrdocs::TypeInfo&]: Assertion 'get() != pointer()' failed.
PLEASE submit a bug report to https://github.com/cppalliance/mrdocs/issues/ and include the crash backtrace.
 #0 0x000000000327dc20 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/mrdocs-0.0.3/bin/mrdocs+0x327dc20)
 #1 0x000000000327ab9b SignalHandler(int) Signals.cpp:0:0
 #2 0x00000000033a87b0 __restore_rt libc_sigaction.o:0:0
 #3 0x00000000033cc35c __pthread_kill (/opt/mrdocs-0.0.3/bin/mrdocs+0x33cc35c)
 #4 0x00000000033a872e raise (/opt/mrdocs-0.0.3/bin/mrdocs+0x33a872e)
 #5 0x000000000043cb39 abort (/opt/mrdocs-0.0.3/bin/mrdocs+0x43cb39)
 #6 0x00000000032aefed (/opt/mrdocs-0.0.3/bin/mrdocs+0x32aefed)
 #7 0x00000000005b2f57 clang::mrdocs::TagfileWriter::writeFunctionMember(clang::mrdocs::FunctionInfo const&) (/opt/mrdocs-0.0.3/bin/mrdocs+0x5b2f57)
 #8 0x00000000005bc738 clang::mrdocs::TagfileWriter::writeNamespace(clang::mrdocs::NamespaceInfo const&) (/opt/mrdocs-0.0.3/bin/mrdocs+0x5bc738)
 #9 0x00000000005bc5bc clang::mrdocs::TagfileWriter::writeNamespace(clang::mrdocs::NamespaceInfo const&) (/opt/mrdocs-0.0.3/bin/mrdocs+0x5bc5bc)
#10 0x00000000005bd838 clang::mrdocs::TagfileWriter::build() (/opt/mrdocs-0.0.3/bin/mrdocs+0x5bd838)
#11 0x0000000000586fa2 clang::mrdocs::hbs::HandlebarsGenerator::build(std::basic_string_view<char, std::char_traits<char>>, clang::mrdocs::Corpus const&) const (/opt/mrdocs-0.0.3/bin/mrdocs+0x586fa2)
#12 0x00000000005418ec clang::mrdocs::Generator::build(clang::mrdocs::Corpus const&) const (/opt/mrdocs-0.0.3/bin/mrdocs+0x5418ec)
#13 0x000000000049616a clang::mrdocs::DoGenerateAction(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, clang::mrdocs::ReferenceDirectories const&, char const**) (/opt/mrdocs-0.0.3/bin/mrdocs+0x49616a)
#14 0x000000000049cf33 clang::mrdocs::mrdocs_main(int, char const**) (/opt/mrdocs-0.0.3/bin/mrdocs+0x49cf33)
#15 0x000000000043d42d main (/opt/mrdocs-0.0.3/bin/mrdocs+0x43d42d)
#16 0x000000000338f7b8 __libc_start_call_main libc-start.o:0:0
#17 0x0000000003391980 __libc_start_main (/opt/mrdocs-0.0.3/bin/mrdocs+0x3391980)
#18 0x000000000048cda5 _start (/opt/mrdocs-0.0.3/bin/mrdocs+0x48cda5)
@alandefreitas
Copy link
Collaborator

Unfortunately, that doesn't reproduce the issue.

repro::f

Synopsis

Declared in <function-template-template.cpp>

template<template<class...> typename ListType>
constexpr
void
f();

Fortunately, the error is in this tagfile generation #795 and it's the same for #794. I'll adapt the tagfile generator to test these cases.

@alandefreitas
Copy link
Collaborator

OK. I figured this out. MrDocs can correctly extract the template parameter but not the function parameter. That's why the documentation says f() and not f(ListType<int>). When rendering the templates, the missing parameter (nullptr) becomes undefined and that's it. In the tagfile generator, it tries to render the nullptr and that's a segmentation fault. So it's just a feature we have to implement.

@anarthal
Copy link
Author

Just to be clear: I don't need this done - the code that raised this is private. I reported because it was a segfault.

@anarthal
Copy link
Author

BTW - would it make sense somehow attaching version information to MrDocs crashes, so reporting is easier? ATM, running mrdocs --version only outputs a semver string (no build number).

@alandefreitas
Copy link
Collaborator

BTW - would it make sense somehow attaching version information to MrDocs crashes, so reporting is easier? ATM, running mrdocs --version only outputs a semver string (no build number).

Yes. We need to improve this. Whenever we report an error, we include the version and the build:

os << "An issue occurred during execution.\n";
os << "If you believe this is a bug, please report it at https://github.com/cppalliance/mrdocs/issues\n"
"with the following details:\n";
os << fmt::format(" MrDocs Version: {} (Build: {})\n", project_version, project_version_build);

We don't report it in this case because it's an exception, which uses the llvm handle. We need to change this handle or use the same report::error for these exceptions.

alandefreitas added a commit to alandefreitas/mrdocs that referenced this issue Jan 15, 2025
alandefreitas added a commit to alandefreitas/mrdocs that referenced this issue Jan 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants