[llvm-bugs] [Bug 49478] New: SEGV dumping AST while mangling declaration for array member of class template

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Mar 8 11:38:48 PST 2021


https://bugs.llvm.org/show_bug.cgi?id=49478

            Bug ID: 49478
           Summary: SEGV dumping AST while mangling declaration for array
                    member of class template
           Product: clang
           Version: 10.0
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++17
          Assignee: unassignedclangbugs at nondot.org
          Reporter: chris.cleeland at gmail.com
                CC: blitzrakete at gmail.com, erik.pilkington at gmail.com,
                    llvm-bugs at lists.llvm.org, richard-llvm at metafoo.co.uk

Created attachment 24603
  --> https://bugs.llvm.org/attachment.cgi?id=24603&action=edit
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>
>, std::string*, bool*) const::'lambda'()>(long) (/opt/exegy$
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>
>, std::string*, bool*) const (.part.154)
(/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 (https://github.com/llvm/llvm-project.git
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
https://bugs.llvm.org/ 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.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210308/dc28d49f/attachment-0001.html>


More information about the llvm-bugs mailing list