[llvm-bugs] [Bug 42749] New: Segmentation fault when using variadic templates combined with lambda defined inside function template and decltype(parameter) as return type

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Jul 24 16:29:52 PDT 2019


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

            Bug ID: 42749
           Summary: Segmentation fault when using variadic templates
                    combined with lambda defined inside function template
                    and decltype(parameter) as return type
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++14
          Assignee: unassignedclangbugs at nondot.org
          Reporter: david at doublewise.net
                CC: blitzrakete at gmail.com, erik.pilkington at gmail.com,
                    llvm-bugs at lists.llvm.org, richard-llvm at metafoo.co.uk

The following C++14 code causes a segmentation fault on clang 7.0.0, 8.0.0, and
trunk. It worked on clang 6.0.0.



template<typename T>
auto indirect(T value) {
        return [](auto) -> decltype(value) { return 1; };
}

template<typename... Args>
int ignore(Args...) {
    return 1;
}

template<typename... Types>
int fold = ignore(indirect(Types())(1)...);

int result = fold<int>;





Stack dump:

0.      Program arguments:
/opt/compiler-explorer/clang-trunk-20190722/bin/clang-10 -cc1 -triple
x86_64-unknown-linux-gnu -S -disable-free -disable-llvm-verifier
-discard-value-names -main-file-name example.cpp -mrelocation-model static
-mthread-model posix -mframe-pointer=all -fmath-errno -masm-verbose
-mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64
-dwarf-column-info -debug-info-kind=limited -dwarf-version=4
-debugger-tuning=gdb -coverage-notes-file /home/ubuntu/./output.gcno
-resource-dir /opt/compiler-explorer/clang-trunk-20190722/lib/clang/10.0.0
-isystem /opt/compiler-explorer/libs/rangesv3/trunk/include -internal-isystem
/opt/compiler-explorer/gcc-8.3.0/lib/gcc/x86_64-linux-gnu/8.3.0/../../../../include/c++/8.3.0
-internal-isystem
/opt/compiler-explorer/gcc-8.3.0/lib/gcc/x86_64-linux-gnu/8.3.0/../../../../include/c++/8.3.0/x86_64-linux-gnu
-internal-isystem
/opt/compiler-explorer/gcc-8.3.0/lib/gcc/x86_64-linux-gnu/8.3.0/../../../../include/c++/8.3.0/backward
-internal-isystem /usr/local/include -internal-isystem
/opt/compiler-explorer/clang-trunk-20190722/lib/clang/10.0.0/include
-internal-externc-isystem /usr/include/x86_64-linux-gnu
-internal-externc-isystem /include -internal-externc-isystem /usr/include
-std=c++14 -fdeprecated-macro -fdebug-compilation-dir /home/ubuntu
-ferror-limit 19 -fmessage-length 0 -fobjc-runtime=gcc -fcxx-exceptions
-fexceptions -fdiagnostics-show-option -fcolor-diagnostics -mllvm
--x86-asm-syntax=intel -faddrsig -o ./output.s -x c++ <source> 

1.      <eof> parser at end of file

2.      <source>:12:5: instantiating variable definition 'fold<int>'

3.      <source>:12:5: instantiating variable definition 'fold<int>'

 #0 0x000055f457cb25ba llvm::sys::PrintStackTrace(llvm::raw_ostream&)
(/opt/compiler-explorer/clang-trunk-20190722/bin/clang-10+0x27dc5ba)

 #1 0x000055f457cb0374 llvm::sys::RunSignalHandlers()
(/opt/compiler-explorer/clang-trunk-20190722/bin/clang-10+0x27da374)

 #2 0x000055f457cb04b2 SignalHandler(int)
(/opt/compiler-explorer/clang-trunk-20190722/bin/clang-10+0x27da4b2)

 #3 0x00007fba2905a890 __restore_rt
(/lib/x86_64-linux-gnu/libpthread.so.0+0x12890)

 #4 0x000055f45952ad19 clang::Sema::tryCaptureVariable(clang::VarDecl*,
clang::SourceLocation, clang::Sema::TryCaptureKind, clang::SourceLocation,
bool, clang::QualType&, clang::QualType&, unsigned int const*)
(/opt/compiler-explorer/clang-trunk-20190722/bin/clang-10+0x4054d19)

 #5 0x000055f45952d041 clang::Sema::NeedToCaptureVariable(clang::VarDecl*,
clang::SourceLocation)
(/opt/compiler-explorer/clang-trunk-20190722/bin/clang-10+0x4057041)

 #6 0x000055f4595485b6 clang::Sema::BuildDeclRefExpr(clang::ValueDecl*,
clang::QualType, clang::ExprValueKind, clang::DeclarationNameInfo const&,
clang::NestedNameSpecifierLoc, clang::NamedDecl*, clang::SourceLocation,
clang::TemplateArgumentListInfo const*)
(/opt/compiler-explorer/clang-trunk-20190722/bin/clang-10+0x40725b6)

 #7 0x000055f4595487d8 clang::Sema::BuildDeclRefExpr(clang::ValueDecl*,
clang::QualType, clang::ExprValueKind, clang::DeclarationNameInfo const&,
clang::CXXScopeSpec const*, clang::NamedDecl*, clang::SourceLocation,
clang::TemplateArgumentListInfo const*)
(/opt/compiler-explorer/clang-trunk-20190722/bin/clang-10+0x40727d8)

 #8 0x000055f459548c15
clang::Sema::BuildDeclarationNameExpr(clang::CXXScopeSpec const&,
clang::DeclarationNameInfo const&, clang::NamedDecl*, clang::NamedDecl*,
clang::TemplateArgumentListInfo const*, bool)
(/opt/compiler-explorer/clang-trunk-20190722/bin/clang-10+0x4072c15)

 #9 0x000055f45983dc11 clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformDeclRefExpr(clang::DeclRefExpr*)
(/opt/compiler-explorer/clang-trunk-20190722/bin/clang-10+0x4367c11)

#10 0x000055f459827f7c clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformExpr(clang::Expr*)
(/opt/compiler-explorer/clang-trunk-20190722/bin/clang-10+0x4351f7c)

#11 0x000055f45982fca5 clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformType(clang::TypeLocBuilder&,
clang::TypeLoc)
(/opt/compiler-explorer/clang-trunk-20190722/bin/clang-10+0x4359ca5)

#12 0x000055f459841b01
clang::Sema::SubstFunctionDeclType(clang::TypeSourceInfo*,
clang::MultiLevelTemplateArgumentList const&, clang::SourceLocation,
clang::DeclarationName, clang::CXXRecordDecl*, clang::Qualifiers)
(/opt/compiler-explorer/clang-trunk-20190722/bin/clang-10+0x436bb01)

#13 0x000055f4598507b4
clang::TemplateDeclInstantiator::SubstFunctionType(clang::FunctionDecl*,
llvm::SmallVectorImpl<clang::ParmVarDecl*>&)
(/opt/compiler-explorer/clang-trunk-20190722/bin/clang-10+0x437a7b4)

#14 0x000055f459861c77
clang::TemplateDeclInstantiator::VisitCXXMethodDecl(clang::CXXMethodDecl*,
clang::TemplateParameterList*,
llvm::Optional<clang::ASTTemplateArgumentListInfo const*>)
(/opt/compiler-explorer/clang-trunk-20190722/bin/clang-10+0x438bc77)

#15 0x000055f45985ee0d clang::Sema::SubstDecl(clang::Decl*,
clang::DeclContext*, clang::MultiLevelTemplateArgumentList const&)
(/opt/compiler-explorer/clang-trunk-20190722/bin/clang-10+0x4388e0d)

#16 0x000055f459816ba7
clang::Sema::FinishTemplateArgumentDeduction(clang::FunctionTemplateDecl*,
llvm::SmallVectorImpl<clang::DeducedTemplateArgument>&, unsigned int,
clang::FunctionDecl*&, clang::sema::TemplateDeductionInfo&,
llvm::SmallVectorImpl<clang::Sema::OriginalCallArg> const*, bool,
llvm::function_ref<bool ()>)
(/opt/compiler-explorer/clang-trunk-20190722/bin/clang-10+0x4340ba7)

#17 0x000055f45981b149
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>)>)
(/opt/compiler-explorer/clang-trunk-20190722/bin/clang-10+0x4345149)

#18 0x000055f459701b4b
clang::Sema::AddMethodTemplateCandidate(clang::FunctionTemplateDecl*,
clang::DeclAccessPair, clang::CXXRecordDecl*, clang::TemplateArgumentListInfo*,
clang::QualType, clang::Expr::Classification, llvm::ArrayRef<clang::Expr*>,
clang::OverloadCandidateSet&, bool, bool)
(/opt/compiler-explorer/clang-trunk-20190722/bin/clang-10+0x422bb4b)

#19 0x000055f459701eb1 clang::Sema::AddMethodCandidate(clang::DeclAccessPair,
clang::QualType, clang::Expr::Classification, llvm::ArrayRef<clang::Expr*>,
clang::OverloadCandidateSet&, bool)
(/opt/compiler-explorer/clang-trunk-20190722/bin/clang-10+0x422beb1)

#20 0x000055f459711f50 clang::Sema::BuildCallToObjectOfClassType(clang::Scope*,
clang::Expr*, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>,
clang::SourceLocation)
(/opt/compiler-explorer/clang-trunk-20190722/bin/clang-10+0x423bf50)

#21 0x000055f45955063b clang::Sema::BuildCallExpr(clang::Scope*, clang::Expr*,
clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>,
clang::SourceLocation, clang::Expr*, bool)
(/opt/compiler-explorer/clang-trunk-20190722/bin/clang-10+0x407a63b)

#22 0x000055f45982d844 clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformCallExpr(clang::CallExpr*)
(/opt/compiler-explorer/clang-trunk-20190722/bin/clang-10+0x4357844)

#23 0x000055f459827e7b clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformExpr(clang::Expr*)
(/opt/compiler-explorer/clang-trunk-20190722/bin/clang-10+0x4351e7b)

#24 0x000055f4598290e6 clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformExprs(clang::Expr* const*, unsigned
int, bool, llvm::SmallVectorImpl<clang::Expr*>&, bool*)
(/opt/compiler-explorer/clang-trunk-20190722/bin/clang-10+0x43530e6)

#25 0x000055f45982d7f6 clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformCallExpr(clang::CallExpr*)
(/opt/compiler-explorer/clang-trunk-20190722/bin/clang-10+0x43577f6)

#26 0x000055f459827e7b clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformExpr(clang::Expr*)
(/opt/compiler-explorer/clang-trunk-20190722/bin/clang-10+0x4351e7b)

#27 0x000055f459828c4b clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformInitializer(clang::Expr*, bool)
(/opt/compiler-explorer/clang-trunk-20190722/bin/clang-10+0x4352c4b)

#28 0x000055f459829ff4 clang::Sema::SubstInitializer(clang::Expr*,
clang::MultiLevelTemplateArgumentList const&, bool)
(/opt/compiler-explorer/clang-trunk-20190722/bin/clang-10+0x4353ff4)

#29 0x000055f4598511af
clang::Sema::InstantiateVariableInitializer(clang::VarDecl*, clang::VarDecl*,
clang::MultiLevelTemplateArgumentList const&)
(/opt/compiler-explorer/clang-trunk-20190722/bin/clang-10+0x437b1af)

#30 0x000055f45985145b
clang::Sema::CompleteVarTemplateSpecializationDecl(clang::VarTemplateSpecializationDecl*,
clang::VarDecl*, clang::MultiLevelTemplateArgumentList const&)
(/opt/compiler-explorer/clang-trunk-20190722/bin/clang-10+0x437b45b)

#31 0x000055f45985f964
clang::Sema::InstantiateVariableDefinition(clang::SourceLocation,
clang::VarDecl*, bool, bool, bool)
(/opt/compiler-explorer/clang-trunk-20190722/bin/clang-10+0x4389964)

#32 0x000055f459860204 clang::Sema::PerformPendingInstantiations(bool)
(/opt/compiler-explorer/clang-trunk-20190722/bin/clang-10+0x438a204)

#33 0x000055f4592e27be
clang::Sema::ActOnEndOfTranslationUnitFragment(clang::Sema::TUFragmentKind)
(.part.1263)
(/opt/compiler-explorer/clang-trunk-20190722/bin/clang-10+0x3e0c7be)

#34 0x000055f4592e2926 clang::Sema::ActOnEndOfTranslationUnit()
(/opt/compiler-explorer/clang-trunk-20190722/bin/clang-10+0x3e0c926)

#35 0x000055f4591e9aed
clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, bool)
(/opt/compiler-explorer/clang-trunk-20190722/bin/clang-10+0x3d13aed)

#36 0x000055f4591dd679 clang::ParseAST(clang::Sema&, bool, bool)
(/opt/compiler-explorer/clang-trunk-20190722/bin/clang-10+0x3d07679)

#37 0x000055f458a084c7 clang::CodeGenAction::ExecuteAction()
(/opt/compiler-explorer/clang-trunk-20190722/bin/clang-10+0x35324c7)

#38 0x000055f458382e69 clang::FrontendAction::Execute()
(/opt/compiler-explorer/clang-trunk-20190722/bin/clang-10+0x2eace69)

#39 0x000055f4583463d5
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&)
(/opt/compiler-explorer/clang-trunk-20190722/bin/clang-10+0x2e703d5)

#40 0x000055f458446873
clang::ExecuteCompilerInvocation(clang::CompilerInstance*)
(/opt/compiler-explorer/clang-trunk-20190722/bin/clang-10+0x2f70873)

#41 0x000055f4561e4ea0 cc1_main(llvm::ArrayRef<char const*>, char const*,
void*) (/opt/compiler-explorer/clang-trunk-20190722/bin/clang-10+0xd0eea0)

#42 0x000055f456143792 main
(/opt/compiler-explorer/clang-trunk-20190722/bin/clang-10+0xc6d792)

#43 0x00007fba27f18b97 __libc_start_main
(/lib/x86_64-linux-gnu/libc.so.6+0x21b97)

#44 0x000055f4561e255a _start
(/opt/compiler-explorer/clang-trunk-20190722/bin/clang-10+0xd0c55a)

clang-10: error: unable to execute command: Segmentation fault (core dumped)

clang-10: error: clang frontend command failed due to signal (use -v to see
invocation)

Compiler returned: 254





See it live: https://godbolt.org/z/8ALVUZ

-- 
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/20190724/32ffaa58/attachment-0001.html>


More information about the llvm-bugs mailing list