[llvm-bugs] [Bug 50656] New: Frontend crashes while parsing invalid string literal operator template

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Jun 10 05:59:47 PDT 2021


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

            Bug ID: 50656
           Summary: Frontend crashes while parsing invalid string literal
                    operator template
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++2a
          Assignee: unassignedclangbugs at nondot.org
          Reporter: john at jwlawson.co.uk
                CC: blitzrakete at gmail.com, erik.pilkington at gmail.com,
                    llvm-bugs at lists.llvm.org, richard-llvm at metafoo.co.uk

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: https://godbolt.org/z/7f75z9dK7

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>
>, std::__cxx11::basic_string<char, std::char_traits<char>,
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>
>, std::__cxx11::basic_string<char, std::char_traits<char>,
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

-- 
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/20210610/13d8914e/attachment.html>


More information about the llvm-bugs mailing list