Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

Variadic template argument deduction - strange error and segfault in recent clang #33657

Open Quuxplusone opened 7 years ago

Quuxplusone commented 7 years ago
Bugzilla Link PR34685
Status NEW
Importance P enhancement
Reported by Nils Wentzell (nils.wentzell@gmail.com)
Reported on 2017-09-20 06:10:39 -0700
Last modified on 2017-09-20 06:11:34 -0700
Version trunk
Hardware PC Linux
CC dgregor@apple.com, llvm-bugs@lists.llvm.org
Fixed by commit(s)
Attachments clang_bug-230866.cpp (131010 bytes, text/x-c++src)
clang_bug-230866.sh (2807 bytes, application/x-shellscript)
Blocks
Blocked by
See also
Created attachment 19179
preprocessed source

The following code-snipped produces an error message and a subsequent segfault
with both clang 5.0.0 and the current master(7a69440) branch. It compiles fine
with any c++11 compliant g++.

#include <initializer_list>

template <typename... T> struct B {};
template <typename T> struct gf {};
template <typename... A> B<A...> make_B(std::initializer_list<gf<A...>> const
&V) { return {}; }

int main() {
  auto x = gf<int>{};
  auto b = make_B<int>({x, x, x}); // clang segfault
  //auto b = make_B({x, x, x}); // ok
}

The error message reads

test.cpp:5:26: error: too many template arguments for class template 'gf'
template <typename... A> B<A...> make_B(std::initializer_list<gf<A...>> const
&V) { return {}; }
                                               ^
test.cpp:9:12: note: in instantiation of function template specialization
'make_B<int>'
requested here
  auto b = make_B<int>({x, x, x}); // clang crash
                  ^
test.cpp:4:30: note: template is declared here
template <typename T> struct gf {};

Why does clang report an error here? The number of template arguments deduced
for gf in the call to make_B<int> should be one.

The crash backtrace reads

#0 0x0000564f5228774a llvm::sys::PrintStackTrace(llvm::raw_ostream&)
(/home/nwentzel/opt/llvm-5.0/bin/clang-5.0+0x1db874a)
#1 0x0000564f52285606 llvm::sys::RunSignalHandlers() (/home/nwentzel/opt/llvm-
5.0/bin/clang-5.0+0x1db6606)
#2 0x0000564f5228574c SignalHandler(int) (/home/nwentzel/opt/llvm-5.0/bin/clang-
5.0+0x1db674c)
#3 0x00007f16fe149da0 __restore_rt (/usr/lib/libpthread.so.0+0x11da0)
#4 0x0000564f536c376c CheckOriginalCallArgDeduction(clang::Sema&,
clang::Sema::OriginalCallArg, clang::QualType) [clone .isra.1573]
(/home/nwentzel/opt/llvm-5.0/bin/clang-5.0+0x31f476c)
#5 0x0000564f536f1e74
clang::Sema::FinishTemplateArgumentDeduction(clang::FunctionTemplateDecl*,
llvm::SmallVectorImpl<clang::DeducedTemplateArgument>&, unsigned int,
clang::FunctionDecl*&, clang::sema::TemplateDeductionInfo&,
llvm::SmallVectorImpl<clang::Sema::OriginalCallArg> co$
st*, bool, llvm::function_ref<bool ()>) (/home/nwentzel/opt/llvm-5.0/bin/clang-
5.0+0x3222e74)
#6 0x0000564f536f68b7
clang::Sema::DeduceTemplateArguments(clang::FunctionTemplateDecl*,
clang::TemplateArgumentListInfo*, llvm::ArrayRef<clang::Expr*>,
clang::FunctionDecl*&, clang::sema::TemplateDeductionInfo&, bool,
llvm::function_ref<bool (llvm::ArrayRef<clang::QualType>)>) (/$
ome/nwentzel/opt/llvm-5.0/bin/clang-5.0+0x32278b7)
#7 0x0000564f53611107
clang::Sema::AddTemplateOverloadCandidate(clang::FunctionTemplateDecl*,
clang::DeclAccessPair, clang::TemplateArgumentListInfo*,
llvm::ArrayRef<clang::Expr*>, clang::OverloadCandidateSet&, bool, bool)
(/home/nwentzel/opt/llvm-5.0/bin/clang-5.0+0x3142107)      #8
0x0000564f5361337a
clang::Sema::AddOverloadedCallCandidates(clang::UnresolvedLookupExpr*,
llvm::ArrayRef<clang::Expr*>, clang::OverloadCandidateSet&, bool)
(/home/nwentzel/opt/llvm-5.0/bin/clang-5.0+0x314437a)
#9 0x0000564f53613623 clang::Sema::buildOverloadedCallSet(clang::Scope*,
clang::Expr*, clang::UnresolvedLookupExpr*,
llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation,
clang::OverloadCandidateSet*, clang::ActionResult<clang::Expr*, true>*)
(/home/nwentzel/opt/llvm-5.0/bin$clang-5.0+0x3144623)
#10 0x0000564f5361748a clang::Sema::BuildOverloadedCallExpr(clang::Scope*,
clang::Expr*, clang::UnresolvedLookupExpr*, clang::SourceLocation,
llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, clang::Expr*, bool,
bool) (/home/nwentzel/opt/llvm-5.0/bin/clang-5.0+0x314848a) #11
0x0000564f5349865b clang::Sema::ActOnCallExpr(clang::Scope*, clang::Expr*,
clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>,
clang::SourceLocation, clang::Expr*, bool) (/home/nwentzel/opt/llvm-
5.0/bin/clang-5.0+0x2fc965b)
#12 0x0000564f5309e87e
clang::Parser::ParsePostfixExpressionSuffix(clang::ActionResult<clang::Expr*,
true>) (/home/nwentzel/opt/llvm-5.0/bin/clang-5.0+0x2bcf87e)
#13 0x0000564f53099acb clang::Parser::ParseCastExpression(bool, bool, bool&,
clang::Parser::TypeCastState, bool) (/home/nwentzel/opt/llvm-5.0/bin/clang-
5.0+0x2bcaacb)
#14 0x0000564f5309beb4 clang::Parser::ParseCastExpression(bool, bool,
clang::Parser::TypeCastState, bool) (/home/nwentzel/opt/llvm-5.0/bin/clang-
5.0+0x2bcceb4)
#15 0x0000564f53099aa9 clang::Parser::ParseCastExpression(bool, bool, bool&,
clang::Parser::TypeCastState, bool) (/home/nwentzel/opt/llvm-5.0/bin/clang-
5.0+0x2bcaaa9)
#16 0x0000564f5309beb4 clang::Parser::ParseCastExpression(bool, bool,
clang::Parser::TypeCastState, bool) (/home/nwentzel/opt/llvm-5.0/bin/clang-
5.0+0x2bcceb4)
#17 0x0000564f5309d53c
clang::Parser::ParseAssignmentExpression(clang::Parser::TypeCastState)
(/home/nwentzel/opt/llvm-5.0/bin/clang-5.0+0x2bce53c)
#18 0x0000564f53069eeb
clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&,
clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*)
(/home/nwentzel/opt/llvm-5.0/bin/clang-5.0+0x2b9aeeb)
#19 0x0000564f5307a650 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&,
unsigned int, clang::SourceLocation*, clang::Parser::ForRangeInit*)
(/home/nwentzel/opt/llvm-5.0/bin/clang-5.0+0x2bab650)
#20 0x0000564f5307d444 clang::Parser::ParseSimpleDeclaration(unsigned int,
clang::SourceLocation&, clang::Parser::ParsedAttributesWithRange&, bool,
clang::Parser::ForRangeInit*) (/home/nwentzel/opt/llvm-5.0/bin/clang-
5.0+0x2bae444)
#21 0x0000564f5307d6cb clang::Parser::ParseDeclaration(unsigned int,
clang::SourceLocation&, clang::Parser::ParsedAttributesWithRange&)
(/home/nwentzel/opt/llvm-5.0/bin/clang-5.0+0x2bae6cb)
#22 0x0000564f530e2ab9
clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*,
32u>&, clang::Parser::AllowedConstructsKind, clang::SourceLocation*,
clang::Parser::ParsedAttributesWithRange&) (/home/nwentzel/opt/llvm-
5.0/bin/clang-5.0+0x2c13ab9)
#23 0x0000564f530e3160
clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*,
32u>&, clang::Parser::AllowedConstructsKind, clang::SourceLocation*)
(/home/nwentzel/opt/llvm-5.0/bin/clang-5.0+0x2c14160)
#24 0x0000564f530e6f8c clang::Parser::ParseCompoundStatementBody(bool)
(/home/nwentzel/opt/llvm-5.0/bin/clang-5.0+0x2c17f8c)
#25 0x0000564f530e980b clang::Parser::ParseFunctionStatementBody(clang::Decl*,
clang::Parser::ParseScope&) (/home/nwentzel/opt/llvm-5.0/bin/clang-
5.0+0x2c1a80b)
#26 0x0000564f53059ed5
clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&,
clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*)
(/home/nwentzel/opt/llvm-5.0/bin/clang-5.0+0x2b8aed5)
#27 0x0000564f5307a503 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&,
unsigned int, clang::SourceLocation*, clang::Parser::ForRangeInit*)
(/home/nwentzel/opt/llvm-5.0/bin/clang-5.0+0x2bab503)
#28 0x0000564f53054641
clang::Parser::ParseDeclOrFunctionDefInternal(clang::Parser::ParsedAttributesWithRange&,
clang::ParsingDeclSpec&, clang::AccessSpecifier) (/home/nwentzel/opt/llvm-
5.0/bin/clang-5.0+0x2b85641)
#29 0x0000564f53054c91
clang::Parser::ParseDeclarationOrFunctionDefinition(clang::Parser::ParsedAttributesWithRange&,
clang::ParsingDeclSpec*, clang::AccessSpecifier) [clone .part.150]
(/home/nwentzel/opt/llvm-5.0/bin/clang-5.0+0x2b85c91)
#30 0x0000564f5305b7a5
clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&,
clang::ParsingDeclSpec*) (/home/nwentzel/opt/llvm-5.0/bin/clang-5.0+0x2b8c7a5)
#31 0x0000564f5305c8a6
clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&)
(/home/nwentzel/opt/llvm-5.0/bin/clang-5.0+0x2b8d8a6)
#32 0x0000564f53050da2 clang::ParseAST(clang::Sema&, bool, bool)
(/home/nwentzel/opt/llvm-5.0/bin/clang-5.0+0x2b81da2)
#33 0x0000564f52b6af37 clang::CodeGenAction::ExecuteAction()
(/home/nwentzel/opt/llvm-5.0/bin/clang-5.0+0x269bf37)
#34 0x0000564f528259a6 clang::FrontendAction::Execute()
(/home/nwentzel/opt/llvm-5.0/bin/clang-5.0+0x23569a6)
#35 0x0000564f527eff8c
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&)
(/home/nwentzel/opt/llvm-5.0/bin/clang-5.0+0x2320f8c)
#36 0x0000564f528d39e3
clang::ExecuteCompilerInvocation(clang::CompilerInstance*)
(/home/nwentzel/opt/llvm-5.0/bin/clang-5.0+0x24049e3)
#37 0x0000564f50d6f048 cc1_main(llvm::ArrayRef<char const*>, char const*,
void*) (/home/nwentzel/opt/llvm-5.0/bin/clang-5.0+0x8a0048)
#38 0x0000564f50cf7e48 main (/home/nwentzel/opt/llvm-5.0/bin/clang-5.0+0x828e48)
#39 0x00007f16fcc28f6a __libc_start_main (/usr/lib/libc.so.6+0x20f6a)
#40 0x0000564f50d6c8ca _start (/home/nwentzel/opt/llvm-5.0/bin/clang-
5.0+0x89d8ca)
Stack dump:
0.      Program arguments: /home/nwentzel/opt/llvm-5.0/bin/clang-5.0 -cc1 -
triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all -disable-free -disable-
llvm-verifier -discard-value-names -main-file-name clang_bug.cpp -mrelocation-
model static -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
/home/nwentzel/opt/llvm-5.0/lib/clang/5.0.0 -I/usr/include/c++/7.1.1/x86_64-pc-
linux-gnu -I/usr/include/c++/7.1.1 -I/usr/inclu$
e/python2.7 -I/home/nwentzel/opt/cubature-1.0.2 -I/usr/include/eigen3 -
I/home/nwentzel/opt/clion-2017.2/include -I/home/nwentzel/opt/pomerol/include -
I/home/nwentzel/opt/triqs/include -I/home/nwentzel/opt/gperftools/include -
I/home/nwentzel/opt/llvm-5.0/include -I/usr/include/c++/$
.1.1/x86_64-pc-linux-gnu -I/usr/include/c++/7.1.1 -I/usr/include/python2.7 -
I/home/nwentzel/opt/cubature-1.0.2 -I/usr/include/eigen3 -I. -internal-isystem
/usr/lib64/gcc/x86_64-pc-linux-gnu/7.2.0/../../../../include/c++/7.2.0 -
internal-isystem /usr/lib64/gcc/x86_64-pc-linux-gnu/7.$
.0/../../../../include/c++/7.2.0/x86_64-pc-linux-gnu -internal-isystem
/usr/lib64/gcc/x86_64-pc-linux-gnu/7.2.0/../../../../include/c++/7.2.0/backward
-internal-isystem /usr/local/include -internal-isystem /home/nwentzel/opt/llvm-
5.0/lib/clang/5.0.0/include -internal-externc-isyst$
m /include -internal-externc-isystem /usr/include -std=c++11 -fdeprecated-macro
-fdebug-compilation-dir /home/nwentzel/Dropbox/Coding/TESTS -ferror-limit 19 -
fmessage-length 282 -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -
fdiagnostics-show-option -fcolor-diagnostics -o /tmp/$
lang_bug-65b1de.o -x c++ clang_bug.cpp
1.      clang_bug.cpp:11:32: current parser token ')'
2.      clang_bug.cpp:9:12: parsing function body 'main'
3.      clang_bug.cpp:9:12: in compound statement ('{}')
clang-5.0: error: unable to execute command: Segmentation fault (core dumped)
clang-5.0: error: clang frontend command failed due to signal (use -v to see
invocation)
clang version 5.0.0 (https://github.com/llvm-mirror/clang
7e8743f82ac7957c66d9c2444996be5b1218673b) (https://github.com/llvm-mirror/llvm
657c31173ea30090583e40c7a9204561d9c2d8c4)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/nwentzel/opt/llvm-5.0/bin
clang-5.0: note: diagnostic msg: PLEASE submit a bug report to
http://llvm.org/bugs/ and include the crash backtrace, preprocessed source, and
associated run script.
clang-5.0: note: diagnostic msg:
Quuxplusone commented 7 years ago

Attached clang_bug-230866.cpp (131010 bytes, text/x-c++src): preprocessed source

Quuxplusone commented 7 years ago

Attached clang_bug-230866.sh (2807 bytes, application/x-shellscript): run script