[llvm-bugs] [Bug 39870] New: Compiler crashes with some invalid templates

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Dec 3 09:07:03 PST 2018


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

            Bug ID: 39870
           Summary: Compiler crashes with some invalid templates
           Product: clang
           Version: 7.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++'17
          Assignee: unassignedclangbugs at nondot.org
          Reporter: exyi at exyi.cz
                CC: blitzrakete at gmail.com, erik.pilkington at gmail.com,
                    llvm-bugs at lists.llvm.org, richard-llvm at metafoo.co.uk

Created attachment 21190
  --> https://bugs.llvm.org/attachment.cgi?id=21190&action=edit
The files clang told me to attach

When I try to compile using `clang++ database/test.cpp -std=c++17`
```
template<typename A> struct X { };
struct Y { X() { } };
```

it crashes. I know that the program is not valid, but the compiler
should not segfault on that.

This is the output of the compiler:

```
test.cpp:2:12: error: deduction guide must be declared in the same scope as
template 'X'
struct Y { X() { } };
           ^
test.cpp:1:29: note: template is declared here
template<typename A> struct X { };
                            ^
test.cpp:2:12: error: deduction guide declaration without trailing return type
struct Y { X() { } };
           ^
test.cpp:2:12: error: deduction guide cannot have a function definition
test.cpp:2:12: error: deduction guide has different access from the
corresponding member template
test.cpp:1:1: note: member template declared private here
template<typename A> struct X { };
^
Stack dump:
0.      Program arguments: /usr/bin/clang-7 -cc1 -triple x86_64-pc-linux-gnu
-emit-llvm-bc -emit-llvm-uselists -save-temps=cwd -disable-free
-disable-llvm-verifier -discard-value-names -main-file-name test.cpp
-mrelocation-model pic -pic-level 2 -pic-is-pie -mthread-model posix
-mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases
-munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info
-debugger-tuning=gdb -resource-dir /usr/lib/clang/7.0.0 -O0 -std=c++17
-fdeprecated-macro -fdebug-compilation-dir /home/exyi/skola/c++/database
-ferror-limit 19 -fmessage-length 0 -stack-protector 2 -fobjc-runtime=gcc
-fcxx-exceptions -fexceptions -fdiagnostics-show-option -disable-llvm-passes -o
test.bc -x c++-cpp-output test.ii -faddrsig 
1.      test.cpp:2:16: current parser token '{'
2.      test.cpp:2:1: parsing struct/union/class body 'Y'
#0 0x00007f92b7fb7b1b llvm::sys::PrintStackTrace(llvm::raw_ostream&)
(/usr/bin/../lib/libLLVM-7.so+0x8feb1b)
#1 0x00007f92b7fb5f74 llvm::sys::RunSignalHandlers()
(/usr/bin/../lib/libLLVM-7.so+0x8fcf74)
#2 0x00007f92b7fb60fe (/usr/bin/../lib/libLLVM-7.so+0x8fd0fe)
#3 0x00007f92b68c3e00 __restore_rt (/usr/bin/../lib/libc.so.6+0x37e00)
#4 0x00007f92b55d7c4a clang::Sema::ActOnCXXMemberDeclarator(clang::Scope*,
clang::AccessSpecifier, clang::Declarator&,
llvm::MutableArrayRef<clang::TemplateParameterList*>, clang::Expr*,
clang::VirtSpecifiers const&, clang::InClassInitStyle)
(/usr/bin/../lib/../lib/libclangSema.so.7+0x2ffc4a)
#5 0x00007f92b5aa20d3
clang::Parser::ParseCXXInlineMethodDef(clang::AccessSpecifier,
clang::ParsedAttributes&, clang::ParsingDeclarator&,
clang::Parser::ParsedTemplateInfo const&, clang::VirtSpecifiers const&,
clang::SourceLocation) (/usr/bin/../lib/../lib/libclangParse.so.7+0x2f0d3)
#6 0x00007f92b5ad26ad
clang::Parser::ParseCXXClassMemberDeclaration(clang::AccessSpecifier,
clang::ParsedAttributes&, clang::Parser::ParsedTemplateInfo const&,
clang::ParsingDeclRAIIObject*)
(/usr/bin/../lib/../lib/libclangParse.so.7+0x5f6ad)
#7 0x00007f92b5ad3fbf
clang::Parser::ParseCXXClassMemberDeclarationWithPragmas(clang::AccessSpecifier&,
clang::Parser::ParsedAttributesWithRange&, clang::TypeSpecifierType,
clang::Decl*) (/usr/bin/../lib/../lib/libclangParse.so.7+0x60fbf)
#8 0x00007f92b5ad4850
clang::Parser::ParseCXXMemberSpecification(clang::SourceLocation,
clang::SourceLocation, clang::Parser::ParsedAttributesWithRange&, unsigned int,
clang::Decl*) (/usr/bin/../lib/../lib/libclangParse.so.7+0x61850)
#9 0x00007f92b5ad7409 clang::Parser::ParseClassSpecifier(clang::tok::TokenKind,
clang::SourceLocation, clang::DeclSpec&, clang::Parser::ParsedTemplateInfo
const&, clang::AccessSpecifier, bool, clang::Parser::DeclSpecContext,
clang::Parser::ParsedAttributesWithRange&)
(/usr/bin/../lib/../lib/libclangParse.so.7+0x64409)
#10 0x00007f92b5ab51eb
clang::Parser::ParseDeclarationSpecifiers(clang::DeclSpec&,
clang::Parser::ParsedTemplateInfo const&, clang::AccessSpecifier,
clang::Parser::DeclSpecContext, clang::Parser::LateParsedAttrList*)
(/usr/bin/../lib/../lib/libclangParse.so.7+0x421eb)
#11 0x00007f92b5b44b3a
clang::Parser::ParseDeclOrFunctionDefInternal(clang::Parser::ParsedAttributesWithRange&,
clang::ParsingDeclSpec&, clang::AccessSpecifier)
(/usr/bin/../lib/../lib/libclangParse.so.7+0xd1b3a)
#12 0x00007f92b5b458a2 (/usr/bin/../lib/../lib/libclangParse.so.7+0xd28a2)
#13 0x00007f92b5b4b131
clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&,
clang::ParsingDeclSpec*) (/usr/bin/../lib/../lib/libclangParse.so.7+0xd8131)
#14 0x00007f92b5b4bd7a
clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&)
(/usr/bin/../lib/../lib/libclangParse.so.7+0xd8d7a)
#15 0x00007f92b5a9d828 clang::ParseAST(clang::Sema&, bool, bool)
(/usr/bin/../lib/../lib/libclangParse.so.7+0x2a828)
#16 0x00007f92b71e9d38 clang::CodeGenAction::ExecuteAction()
(/usr/bin/../lib/libclangCodeGen.so.7+0x2cdd38)
#17 0x00007f92b6cc0856 clang::FrontendAction::Execute()
(/usr/bin/../lib/libclangFrontend.so.7+0xd7856)
#18 0x00007f92b6c7f559
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&)
(/usr/bin/../lib/libclangFrontend.so.7+0x96559)
#19 0x00007f92b6be599d
clang::ExecuteCompilerInvocation(clang::CompilerInstance*)
(/usr/bin/../lib/libclangFrontendTool.so.7+0x499d)
#20 0x00005594c12dac39 cc1_main(llvm::ArrayRef<char const*>, char const*,
void*) (/usr/bin/clang-7+0x11c39)
#21 0x00005594c12d7946 main (/usr/bin/clang-7+0xe946)
#22 0x00007f92b68b0223 __libc_start_main (/usr/bin/../lib/libc.so.6+0x24223)
#23 0x00005594c12d85ae _start (/usr/bin/clang-7+0xf5ae)
clang-7: error: unable to execute command: Segmentation fault (core dumped)
clang-7: error: clang frontend command failed due to signal (use -v to see
invocation)
clang version 7.0.0 (tags/RELEASE_700/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
clang-7: note: diagnostic msg: PLEASE submit a bug report to  and include the
crash backtrace, preprocessed source, and associated run script.
clang-7: note: diagnostic msg: 
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang-7: note: diagnostic msg: /tmp/test-134116.cpp
clang-7: note: diagnostic msg: /tmp/test-134116.sh
clang-7: note: diagnostic msg: 

********************
```

The `.ii` file and crash reporter files are in the attached zip.

-- 
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/20181203/8c06a831/attachment-0001.html>


More information about the llvm-bugs mailing list