<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - SEGV dumping AST while mangling declaration for array member of class template"
href="https://bugs.llvm.org/show_bug.cgi?id=49478">49478</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>SEGV dumping AST while mangling declaration for array member of class template
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>10.0
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>C++17
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>chris.cleeland@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>blitzrakete@gmail.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=24603" name="attach_24603" title="preprocessed format.cpp that provokes segv">attachment 24603</a> <a href="attachment.cgi?id=24603&action=edit" title="preprocessed format.cpp that provokes segv">[details]</a></span>
preprocessed format.cpp that provokes segv
Trying to generate an AST for the following for llvm-10 yields a SEGV and a
"PLEASE file a bug..."
``` name this `format.cpp`
// this breaks in llvm-10
// clang++ -std=c++17 -Xclang -ast-dump=json -fsyntax-only format.cpp
// SEGV
// fix by specifying array size in format
#include <cstdio>
template<unsigned... DIGITS> struct to_printf_format { static const char
format[]; };
#ifdef SHOW_WORKING
template<unsigned... DIGITS> const char
to_printf_format<DIGITS...>::format[4+sizeof...(DIGITS)] = { '%', '0', ('0' +
DIGITS)..., 'u', 0 };
#else
template<unsigned... DIGITS> const char to_printf_format<DIGITS...>::format[] =
{ '%', '0', ('0' + DIGITS)..., 'u', 0 };
#endif
int main()
{
using fmt = to_printf_format<1,2>;
printf("%s\n", fmt::format);
}
```
Program output:
```
Stack dump:
0. Program arguments: clang++ -std=c++17 -Xclang -ast-dump=json
-fsyntax-only /tmp/preproc.cpp
1. <eof> parser at end of file
2. /code/jrickman/cpptmp/format.cpp:12:70: Mangling declaration
'to_printf_format::format'
#0 0x0000000002559fca llvm::sys::PrintStackTrace(llvm::raw_ostream&)
(/opt/exegy/llvm-10/root/usr/bin/clang-10+0x2559fca)
#1 0x0000000002557d94 llvm::sys::RunSignalHandlers()
(/opt/exegy/llvm-10/root/usr/bin/clang-10+0x2557d94)
#2 0x0000000002557feb llvm::sys::CleanupOnSignal(unsigned long)
(/opt/exegy/llvm-10/root/usr/bin/clang-10+0x2557feb)
#3 0x00000000024e5f88 CrashRecoverySignalHandler(int)
(/opt/exegy/llvm-10/root/usr/bin/clang-10+0x24e5f88)
#4 0x00007f700e3ab5f0 __restore_rt (/lib64/libpthread.so.0+0xf5f0)
#5 0x0000000004925d50 (anonymous
namespace)::CXXNameMangler::mangleExpression(clang::Expr const*, unsigned int)
(/opt/exegy/llvm-10/root/usr/bin/clang-10+0x4925d50)
#6 0x0000000004922409 (anonymous
namespace)::CXXNameMangler::mangleType(clang::QualType)
(/opt/exegy/llvm-10/root/usr/bin/clang-10+0x4922409)
#7 0x0000000004928c0c (anonymous
namespace)::CXXNameMangler::mangleName(clang::NamedDecl const*)
(/opt/exegy/llvm-10/root/usr/bin/clang-10+0x4928c0c)
#8 0x000000000492db31 (anonymous
namespace)::ItaniumMangleContextImpl::mangleCXXName(clang::NamedDecl const*,
llvm::raw_ostream&) (/opt/exegy/llvm-10/root/usr/bin/clang-10+0x492db31)
#9 0x00000000049426c3 clang::ASTNameGenerator::getName(clang::Decl const*)
(/opt/exegy/llvm-10/root/usr/bin/clang-10+0x49426c3)
#10 0x0000000004931d5a clang::JSONNodeDumper::VisitNamedDecl(clang::NamedDecl
const*) (/opt/exegy/llvm-10/root/usr/bin/clang-10+0x4931d5a)
#11 0x000000000493a37e clang::JSONNodeDumper::VisitVarDecl(clang::VarDecl
const*) (/opt/exegy/llvm-10/root/usr/bin/clang-10+0x493a37e)
#12 0x0000000004940980 clang::JSONNodeDumper::Visit(clang::Decl const*)
(/opt/exegy/llvm-10/root/usr/bin/clang-10+0x4940980)
#13 0x0000000004750dd9 std::_Function_handler<void (bool), void
clang::NodeStreamer::AddChild<clang::ASTNodeTraverser<clang::JSONDumper,
clang::JSONNodeDumper>::Visit(clang::Decl const*)::'lambda'()>(llvm::Strin$
Ref, clang::JSONDumper)::'lambda'(bool)>::_M_invoke(std::_Any_data const&,
bool&&) (/opt/exegy/llvm-10/root/usr/bin/clang-10+0x4750dd9)
#14 0x0000000004749b37 void
clang::NodeStreamer::AddChild<clang::ASTNodeTraverser<clang::JSONDumper,
clang::JSONNodeDumper>::Visit(clang::Decl const*)::'lambda'()>(llvm::StringRef,
clang::JSONDumper) (.constprop$
1827) (/opt/exegy/llvm-10/root/usr/bin/clang-10+0x4749b37)
#15 0x0000000004749a63 clang::ASTNodeTraverser<clang::JSONDumper,
clang::JSONNodeDumper>::Visit(clang::Decl const*)::'lambda'()::operator()()
const (/opt/exegy/llvm-10/root/usr/bin/clang-10+0x4749a63)
#16 0x0000000004749cfd void
clang::NodeStreamer::AddChild<clang::ASTNodeTraverser<clang::JSONDumper,
clang::JSONNodeDumper>::Visit(clang::Decl const*)::'lambda'()>(llvm::StringRef,
clang::JSONDumper) (.constprop$
1827) (/opt/exegy/llvm-10/root/usr/bin/clang-10+0x4749cfd)
#17 0x0000000004750ce3 clang::Decl::dump(llvm::raw_ostream&, bool,
clang::ASTDumpOutputFormat) const
(/opt/exegy/llvm-10/root/usr/bin/clang-10+0x4750ce3)
#18 0x0000000002ce039d (anonymous
namespace)::ASTPrinter::HandleTranslationUnit(clang::ASTContext&)
(/opt/exegy/llvm-10/root/usr/bin/clang-10+0x2ce039d)
#19 0x0000000003e747d1 clang::ParseAST(clang::Sema&, bool, bool)
(/opt/exegy/llvm-10/root/usr/bin/clang-10+0x3e747d1)
#20 0x0000000002c7fe99 clang::FrontendAction::Execute()
(/opt/exegy/llvm-10/root/usr/bin/clang-10+0x2c7fe99)
#21 0x0000000002c450ea
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&)
(/opt/exegy/llvm-10/root/usr/bin/clang-10+0x2c450ea)
#22 0x0000000002d41d53
clang::ExecuteCompilerInvocation(clang::CompilerInstance*)
(/opt/exegy/llvm-10/root/usr/bin/clang-10+0x2d41d53)
#23 0x0000000000950296 cc1_main(llvm::ArrayRef<char const*>, char const*,
void*) (/opt/exegy/llvm-10/root/usr/bin/clang-10+0x950296)
#24 0x000000000094d77b ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&)
(/opt/exegy/llvm-10/root/usr/bin/clang-10+0x94d77b)
#25 0x0000000002b34845 void llvm::function_ref<void
()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef>
<span class="quote">>, std::string*, bool*) const::'lambda'()>(long) (/opt/exegy$</span >
llvm-10/root/usr/bin/clang-10+0x2b34845)
#26 0x00000000024e6083
llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>)
(/opt/exegy/llvm-10/root/usr/bin/clang-10+0x24e6083)
#27 0x0000000002b3557d
clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef>
<span class="quote">>, std::string*, bool*) const (.part.154)</span >
(/opt/exegy/llvm-10/root/usr/bin/clang-10+0x2b3557d)
#28 0x0000000002b11b78
clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&,
clang::driver::Command const*&) const
(/opt/exegy/llvm-10/root/usr/bin/clang-10+0x2b11b78)
#29 0x0000000002b12447
clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&,
llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&) const
(/opt/exegy/llvm-10/root/usr/bin/clang-$
0+0x2b12447)
#30 0x0000000002b1a28a
clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&,
llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&)
(/opt/exegy/llvm-10/root/usr/bin/clang-10+0x2$
1a28a)
#31 0x00000000008bb986 main (/opt/exegy/llvm-10/root/usr/bin/clang-10+0x8bb986)
#32 0x00007f700cf85505 __libc_start_main (/lib64/libc.so.6+0x22505)
#33 0x000000000094d355 _start
(/opt/exegy/llvm-10/root/usr/bin/clang-10+0x94d355)
clang-10: error: clang frontend command failed due to signal (use -v to see
invocation)
clang version 10.0.0 (<a href="https://github.com/llvm/llvm-project.git">https://github.com/llvm/llvm-project.git</a>
d32170dbd5b0d54436537b6b75beaf44324e0c28)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/exegy/llvm-10/root/usr/bin
clang-10: note: diagnostic msg: PLEASE submit a bug report to
<a href="https://bugs.llvm.org/">https://bugs.llvm.org/</a> and include the crash backtrace, preprocessed source,
and associated run script.
clang-10: error: unable to execute command: Segmentation fault (core dumped)
clang-10: note: diagnostic msg: Error generating preprocessed source(s).
```
Note that adding `-DSHOW_WORKING` to the compile line uses a declaration that
does not dump core. Not sure if that helps. Will be attaching the
preprocessed file separately.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>