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

            Bug ID: 36575
           Summary: Specialization of non-template member class with
                    non-type template function causes crash.
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangb...@nondot.org
          Reporter: crock...@msu.edu
                CC: llvm-bugs@lists.llvm.org

Created attachment 19987
  --> https://bugs.llvm.org/attachment.cgi?id=19987&action=edit
Preprocessed source

Clang fails to instantiate template function in specialization of nested member
class of class template when the function template and class template use
different types of template parameters. Minimal working example is attached.

I am using Ubuntu 17.04, and have reproduced this issue on my system using
clang versions 4, 5, and trunk.

This issue only occurs when (i) the nested class is not a template, and (ii)
the class template uses a type parameter and the function template uses a
non-type parameter, or vise versa. If the class template and function template
both use a type parameter or both use a non-type parameter, then compilation
succeeds.

The stack trace for clang trunk is below. Clang 4 and 5 produce a segmentation
fault (these are non-debug builds). As you can see in the stack trace, an
assertion fails on instantiation of the template function due to the template
argument type. If I had to guess I would say that clang is somehow confusing
the type parameter of the class template and the non-type parameter of the
function template.


clang++ -c -o clang-test.o -O0 -std=c++14 -save-temps clang-test.cpp
clang-7.0:
/home/mike/src/clang/llvm/tools/clang/lib/Sema/SemaTemplate.cpp:6690:
clang::ExprResult
clang::Sema::BuildExpressionFromIntegralTemplateArgument(const
clang::TemplateArgument&, clang::SourceLocation): Assertion `Arg.getKind() ==
TemplateArgument::Integral && "Operation is only valid for integral template
arguments"' failed.
#0 0x0000561a1dd9d191 llvm::sys::PrintStackTrace(llvm::raw_ostream&)
/home/mike/src/clang/llvm/lib/Support/Unix/Signals.inc:398:0
#1 0x0000561a1dd9d224 PrintStackTraceSignalHandler(void*)
/home/mike/src/clang/llvm/lib/Support/Unix/Signals.inc:462:0
#2 0x0000561a1dd9b3f9 llvm::sys::RunSignalHandlers()
/home/mike/src/clang/llvm/lib/Support/Signals.cpp:49:0
#3 0x0000561a1dd9c9fd SignalHandler(int)
/home/mike/src/clang/llvm/lib/Support/Unix/Signals.inc:252:0
#4 0x00007f1ca540e150 __restore_rt
(/lib/x86_64-linux-gnu/libpthread.so.0+0x13150)
#5 0x00007f1ca41150bb gsignal
/build/glibc-itYbWN/glibc-2.26/signal/../sysdeps/unix/sysv/linux/raise.c:51:0
#6 0x00007f1ca4116f5d abort /build/glibc-itYbWN/glibc-2.26/stdlib/abort.c:92:0
#7 0x00007f1ca410cf17 __assert_fail_base
/build/glibc-itYbWN/glibc-2.26/assert/assert.c:92:0
#8 0x00007f1ca410cfc2 (/lib/x86_64-linux-gnu/libc.so.6+0x2efc2)
#9 0x0000561a20619f17
clang::Sema::BuildExpressionFromIntegralTemplateArgument(clang::TemplateArgument
const&, clang::SourceLocation)
/home/mike/src/clang/llvm/tools/clang/lib/Sema/SemaTemplate.cpp:6689:0
#10 0x0000561a20710f7f (anonymous
namespace)::TemplateInstantiator::transformNonTypeTemplateParmRef(clang::NonTypeTemplateParmDecl*,
clang::SourceLocation, clang::TemplateArgument)
/home/mike/src/clang/llvm/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp:1296:0
#11 0x0000561a20710ae3 (anonymous
namespace)::TemplateInstantiator::TransformTemplateParmRefExpr(clang::DeclRefExpr*,
clang::NonTypeTemplateParmDecl*)
/home/mike/src/clang/llvm/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp:1225:0
#12 0x0000561a20711818 (anonymous
namespace)::TemplateInstantiator::TransformDeclRefExpr(clang::DeclRefExpr*)
/home/mike/src/clang/llvm/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp:1402:0
#13 0x0000561a20719f55 clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformExpr(clang::Expr*)
/home/mike/src/clang/build/tools/clang/include/clang/AST/StmtNodes.inc:477:0
#14 0x0000561a2071eaab clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformInitializer(clang::Expr*, bool)
/home/mike/src/clang/llvm/tools/clang/lib/Sema/TreeTransform.h:3356:0
#15 0x0000561a2073d341 clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformReturnStmt(clang::ReturnStmt*)
/home/mike/src/clang/llvm/tools/clang/lib/Sema/TreeTransform.h:6799:0
#16 0x0000561a2071e680 clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformStmt(clang::Stmt*)
/home/mike/src/clang/build/tools/clang/include/clang/AST/StmtNodes.inc:1219:0
#17 0x0000561a20744590 clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformCompoundStmt(clang::CompoundStmt*,
bool) /home/mike/src/clang/llvm/tools/clang/lib/Sema/TreeTransform.h:6439:0
#18 0x0000561a20737c3f clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformCompoundStmt(clang::CompoundStmt*)
/home/mike/src/clang/llvm/tools/clang/lib/Sema/TreeTransform.h:6427:0
#19 0x0000561a2071db3f clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformStmt(clang::Stmt*)
/home/mike/src/clang/build/tools/clang/include/clang/AST/StmtNodes.inc:79:0
#20 0x0000561a20716a29 clang::Sema::SubstStmt(clang::Stmt*,
clang::MultiLevelTemplateArgumentList const&)
/home/mike/src/clang/llvm/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp:2783:0
#21 0x0000561a2076cc9e
clang::Sema::InstantiateFunctionDefinition(clang::SourceLocation,
clang::FunctionDecl*, bool, bool, bool)
/home/mike/src/clang/llvm/tools/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp:3970:0
#22 0x0000561a20622f6a clang::Sema::ActOnExplicitInstantiation(clang::Scope*,
clang::SourceLocation, clang::SourceLocation, clang::Declarator&)
/home/mike/src/clang/llvm/tools/clang/lib/Sema/SemaTemplate.cpp:9294:0
#23 0x0000561a1fa97da6
clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&,
clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*)
/home/mike/src/clang/llvm/tools/clang/lib/Parse/ParseDecl.cpp:2208:0
#24 0x0000561a1fa97971
clang::Parser::ParseDeclarationAfterDeclarator(clang::Declarator&,
clang::Parser::ParsedTemplateInfo const&)
/home/mike/src/clang/llvm/tools/clang/lib/Parse/ParseDecl.cpp:2152:0
#25 0x0000561a1fb41023
clang::Parser::ParseSingleDeclarationAfterTemplate(clang::DeclaratorContext,
clang::Parser::ParsedTemplateInfo const&, clang::ParsingDeclRAIIObject&,
clang::SourceLocation&, clang::AccessSpecifier, clang::AttributeList*)
/home/mike/src/clang/llvm/tools/clang/lib/Parse/ParseTemplate.cpp:308:0
#26 0x0000561a1fb4490c
clang::Parser::ParseExplicitInstantiation(clang::DeclaratorContext,
clang::SourceLocation, clang::SourceLocation, clang::SourceLocation&,
clang::AccessSpecifier)
/home/mike/src/clang/llvm/tools/clang/lib/Parse/ParseTemplate.cpp:1328:0
#27 0x0000561a1fb3ffdf
clang::Parser::ParseDeclarationStartingWithTemplate(clang::DeclaratorContext,
clang::SourceLocation&, clang::AccessSpecifier, clang::AttributeList*)
/home/mike/src/clang/llvm/tools/clang/lib/Parse/ParseTemplate.cpp:36:0
#28 0x0000561a1fa9605b
clang::Parser::ParseDeclaration(clang::DeclaratorContext,
clang::SourceLocation&, clang::Parser::ParsedAttributesWithRange&)
/home/mike/src/clang/llvm/tools/clang/lib/Parse/ParseDecl.cpp:1683:0
#29 0x0000561a1fa72372
clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&,
clang::ParsingDeclSpec*)
/home/mike/src/clang/llvm/tools/clang/lib/Parse/Parser.cpp:786:0
#30 0x0000561a1fa71a07
clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&)
/home/mike/src/clang/llvm/tools/clang/lib/Parse/Parser.cpp:609:0
#31 0x0000561a1fa6d756 clang::ParseAST(clang::Sema&, bool, bool)
/home/mike/src/clang/llvm/tools/clang/lib/Parse/ParseAST.cpp:151:0
#32 0x0000561a1e7731a7 clang::ASTFrontendAction::ExecuteAction()
/home/mike/src/clang/llvm/tools/clang/lib/Frontend/FrontendAction.cpp:1005:0
#33 0x0000561a1ecb2720 clang::CodeGenAction::ExecuteAction()
/home/mike/src/clang/llvm/tools/clang/lib/CodeGen/CodeGenAction.cpp:1041:0
#34 0x0000561a1e772bea clang::FrontendAction::Execute()
/home/mike/src/clang/llvm/tools/clang/lib/Frontend/FrontendAction.cpp:908:0
#35 0x0000561a1e702c20
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&)
/home/mike/src/clang/llvm/tools/clang/lib/Frontend/CompilerInstance.cpp:992:0
#36 0x0000561a1e8cb071
clang::ExecuteCompilerInvocation(clang::CompilerInstance*)
/home/mike/src/clang/llvm/tools/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:255:0
#37 0x0000561a1bacd066 cc1_main(llvm::ArrayRef<char const*>, char const*,
void*) /home/mike/src/clang/llvm/tools/clang/tools/driver/cc1_main.cpp:221:0
#38 0x0000561a1bac1dad ExecuteCC1Tool(llvm::ArrayRef<char const*>,
llvm::StringRef)
/home/mike/src/clang/llvm/tools/clang/tools/driver/driver.cpp:309:0
#39 0x0000561a1bac2a6d main
/home/mike/src/clang/llvm/tools/clang/tools/driver/driver.cpp:389:0
#40 0x00007f1ca40ff1c1 __libc_start_main
/build/glibc-itYbWN/glibc-2.26/csu/../csu/libc-start.c:342:0
#41 0x0000561a1babf48a _start
(/home/mike/src/clang/build/bin/clang-7.0+0x1e2c48a)
Stack dump:
0.      Program arguments: /home/mike/src/clang/build/bin/clang-7.0 -cc1
-triple x86_64-unknown-linux-gnu -emit-llvm-bc -emit-llvm-uselists
-disable-free -main-file-name clang-test.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 -coverage-notes-file
/home/mike/code/clang-test/clang-test.gcno -resource-dir
/home/mike/src/clang/build/lib/clang/7.0.0 -O0 -std=c++14 -fdeprecated-macro
-fdebug-compilation-dir /home/mike/code/clang-test -ferror-limit 19
-fmessage-length 205 -fobjc-runtime=gcc -fcxx-exceptions -fexceptions
-fdiagnostics-show-option -fcolor-diagnostics -disable-llvm-passes -o
clang-test.bc -x c++-cpp-output clang-test.ii 
1.      clang-test.cpp:17:32: current parser token ';'
2.      clang-test.cpp:13:9: instantiating function definition
'A<char>::B::f<2>'
clang-7.0: error: unable to execute command: Aborted (core dumped)
clang-7.0: error: clang frontend command failed due to signal (use -v to see
invocation)
clang version 7.0.0 (trunk 326139) (llvm/trunk 326138)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/mike/src/clang/build/bin

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to