<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 - Frontend crashes while parsing invalid string literal operator template"
href="https://bugs.llvm.org/show_bug.cgi?id=50656">50656</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Frontend crashes while parsing invalid string literal operator template
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Windows NT
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>C++2a
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>john@jwlawson.co.uk
</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>When (incorrectly) defining a string literal operator template with a general
type template rather than an NTTP the clang frontend crashes. The following
example show this. Note it's not valid C++, but shouldn't lead to a crash.
Clang 11 will parse this and output an error, while 12 and trunk fail to do so.
#include <array>
#include <cstddef>
#include <iterator>
template<std::size_t N>
struct String {
constexpr String(char const(&chars)[N])
{ std::copy(std::begin(chars), std::end(chars), arr.begin()); }
std::array<char, N> arr;
};
template<typename X> // Should be template<String s>
constexpr auto operator""_x() {
return s;
}
constexpr auto thing = "hello"_x;
See: <a href="https://godbolt.org/z/7f75z9dK7">https://godbolt.org/z/7f75z9dK7</a>
Stack dump:
0. Program arguments: /opt/compiler-explorer/clang-trunk/bin/clang++ -g -o
/app/output.s -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot
-fcolor-diagnostics -fno-crash-diagnostics -std=c++20 <source>
1. <source>:13:31: current parser token '{'
#0 0x000055e81a74cc8f PrintStackTraceSignalHandler(void*) Signals.cpp:0:0
#1 0x000055e81a74ab80 llvm::sys::CleanupOnSignal(unsigned long)
(/opt/compiler-explorer/clang-trunk/bin/clang+++0x32ccb80)
#2 0x000055e81a69fe28 CrashRecoverySignalHandler(int)
CrashRecoveryContext.cpp:0:0
#3 0x00007f3188b263c0 __restore_rt
(/lib/x86_64-linux-gnu/libpthread.so.0+0x153c0)
#4 0x000055e81d01ccb0 clang::Decl::isTemplateParameterPack() const
(/opt/compiler-explorer/clang-trunk/bin/clang+++0x5b9ecb0)
#5 0x000055e81c7ad0ae
clang::Sema::CheckLiteralOperatorDeclaration(clang::FunctionDecl*)
(/opt/compiler-explorer/clang-trunk/bin/clang+++0x532f0ae)
#6 0x000055e81c741966 clang::Sema::CheckFunctionDeclaration(clang::Scope*,
clang::FunctionDecl*, clang::LookupResult&, bool)
(/opt/compiler-explorer/clang-trunk/bin/clang+++0x52c3966)
#7 0x000055e81c7485f2 clang::Sema::ActOnFunctionDeclarator(clang::Scope*,
clang::Declarator&, clang::DeclContext*, clang::TypeSourceInfo*,
clang::LookupResult&, llvm::MutableArrayRef<clang::TemplateParameterList*>,
bool&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x52ca5f2)
#8 0x000055e81c74be4f clang::Sema::HandleDeclarator(clang::Scope*,
clang::Declarator&, llvm::MutableArrayRef<clang::TemplateParameterList*>)
(/opt/compiler-explorer/clang-trunk/bin/clang+++0x52cde4f)
#9 0x000055e81c74c944 clang::Sema::ActOnStartOfFunctionDef(clang::Scope*,
clang::Declarator&, llvm::MutableArrayRef<clang::TemplateParameterList*>,
clang::Sema::SkipBodyInfo*)
(/opt/compiler-explorer/clang-trunk/bin/clang+++0x52ce944)
#10 0x000055e81c4ca5ae
clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&,
clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*)
(/opt/compiler-explorer/clang-trunk/bin/clang+++0x504c5ae)
#11 0x000055e81c5934d9
clang::Parser::ParseSingleDeclarationAfterTemplate(clang::DeclaratorContext,
clang::Parser::ParsedTemplateInfo const&, clang::ParsingDeclRAIIObject&,
clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier)
(/opt/compiler-explorer/clang-trunk/bin/clang+++0x51154d9)
#12 0x000055e81c5963e3
clang::Parser::ParseTemplateDeclarationOrSpecialization(clang::DeclaratorContext,
clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier)
(/opt/compiler-explorer/clang-trunk/bin/clang+++0x51183e3)
#13 0x000055e81c596954
clang::Parser::ParseDeclarationStartingWithTemplate(clang::DeclaratorContext,
clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier)
(/opt/compiler-explorer/clang-trunk/bin/clang+++0x5118954)
#14 0x000055e81c4f48e5
clang::Parser::ParseDeclaration(clang::DeclaratorContext,
clang::SourceLocation&, clang::ParsedAttributesWithRange&,
clang::SourceLocation*)
(/opt/compiler-explorer/clang-trunk/bin/clang+++0x50768e5)
#15 0x000055e81c4cbd82
clang::Parser::ParseExternalDeclaration(clang::ParsedAttributesWithRange&,
clang::ParsingDeclSpec*)
(/opt/compiler-explorer/clang-trunk/bin/clang+++0x504dd82)
#16 0x000055e81c4cd169
clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, bool)
(/opt/compiler-explorer/clang-trunk/bin/clang+++0x504f169)
#17 0x000055e81c4c09f9 clang::ParseAST(clang::Sema&, bool, bool)
(/opt/compiler-explorer/clang-trunk/bin/clang+++0x50429f9)
#18 0x000055e81b667bd2 clang::CodeGenAction::ExecuteAction()
(/opt/compiler-explorer/clang-trunk/bin/clang+++0x41e9bd2)
#19 0x000055e81b022681 clang::FrontendAction::Execute()
(/opt/compiler-explorer/clang-trunk/bin/clang+++0x3ba4681)
#20 0x000055e81afc07a2
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&)
(/opt/compiler-explorer/clang-trunk/bin/clang+++0x3b427a2)
#21 0x000055e81b0ee363
clang::ExecuteCompilerInvocation(clang::CompilerInstance*)
(/opt/compiler-explorer/clang-trunk/bin/clang+++0x3c70363)
#22 0x000055e8185b601c cc1_main(llvm::ArrayRef<char const*>, char const*,
void*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x113801c)
#23 0x000055e8185b21ad ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&)
driver.cpp:0:0
#24 0x000055e81ae6f275 void llvm::function_ref<void
()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef>
<span class="quote">>, std::__cxx11::basic_string<char, std::char_traits<char>,</span >
std::allocator<char> >*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#25 0x000055e81a6a0413
llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>)
(/opt/compiler-explorer/clang-trunk/bin/clang+++0x3222413)
#26 0x000055e81ae7114e
clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef>
<span class="quote">>, std::__cxx11::basic_string<char, std::char_traits<char>,</span >
std::allocator<char> >*, bool*) const
(/opt/compiler-explorer/clang-trunk/bin/clang+++0x39f314e)
#27 0x000055e81ae474ea
clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&,
clang::driver::Command const*&) const
(/opt/compiler-explorer/clang-trunk/bin/clang+++0x39c94ea)
#28 0x000055e81ae4803f
clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&,
llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&) const
(/opt/compiler-explorer/clang-trunk/bin/clang+++0x39ca03f)
#29 0x000055e81ae50fe5
clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&,
llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&)
(/opt/compiler-explorer/clang-trunk/bin/clang+++0x39d2fe5)
#30 0x000055e8184cc2a3 main
(/opt/compiler-explorer/clang-trunk/bin/clang+++0x104e2a3)
#31 0x00007f31885d70b3 __libc_start_main
(/lib/x86_64-linux-gnu/libc.so.6+0x270b3)
#32 0x000055e8185b1d2a _start
(/opt/compiler-explorer/clang-trunk/bin/clang+++0x1133d2a)
clang-13: error: clang frontend command failed with exit code 139 (use -v to
see invocation)
Compiler returned: 139</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>