<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - crash on explicit specialization inside a template class definition"
href="https://bugs.llvm.org/show_bug.cgi?id=39817">39817</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>crash on explicit specialization inside a template class definition
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>Frontend
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>rprichard@google.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>This snippet of code crashes the Clang frontend:
template<typename T> struct Outer {
template<int I> struct Inner {};
template<> struct Inner<0> {
void method(void* p) {
delete static_cast<T*>(p);
}
};
Outer() { Inner<0>().method(0); }
};
Outer<int> outer;
It defines an explicit specialization of a member class template, inside of a
template class definition. The ability to do this was apparently added recently
in C++17:
<a href="http://open-std.org/JTC1/SC22/WG21/docs/cwg_defects.html#727">http://open-std.org/JTC1/SC22/WG21/docs/cwg_defects.html#727</a>
Clang appears to allow the in-class explicit specialization with any -std=
language setting.
It seemed to matter that I used the outer template's T type inside the
specialization.
Clang 6.0.0 rejects the code with an error:
error: explicit specialization of 'Inner' in class scope
Clang 7.0.0 and trunk crash. Here's the crash dump from trunk:
Stack dump:
0. Program arguments:
/opt/compiler-explorer/clang-trunk-20181127/bin/clang-8 -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 -mdisable-fp-elim -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
/tmp/compiler-explorer-compiler1181028-56-22sp7j.7b08g/output.gcno
-resource-dir /opt/compiler-explorer/clang-trunk-20181127/lib/clang/8.0.0
-internal-isystem
/opt/compiler-explorer/gcc-8.2.0/lib/gcc/x86_64-linux-gnu/8.2.0/../../../../include/c++/8.2.0
-internal-isystem
/opt/compiler-explorer/gcc-8.2.0/lib/gcc/x86_64-linux-gnu/8.2.0/../../../../include/c++/8.2.0/x86_64-linux-gnu
-internal-isystem
/opt/compiler-explorer/gcc-8.2.0/lib/gcc/x86_64-linux-gnu/8.2.0/../../../../include/c++/8.2.0/backward
-internal-isystem /usr/local/include -internal-isystem
/opt/compiler-explorer/clang-trunk-20181127/lib/clang/8.0.0/include
-internal-externc-isystem /usr/include/x86_64-linux-gnu
-internal-externc-isystem /include -internal-externc-isystem /usr/include
-fdeprecated-macro -fdebug-compilation-dir
/tmp/compiler-explorer-compiler1181028-56-22sp7j.7b08g -ferror-limit 19
-fmessage-length 0 -fobjc-runtime=gcc -fcxx-exceptions -fexceptions
-fdiagnostics-show-option -fcolor-diagnostics -o
/tmp/compiler-explorer-compiler1181028-56-22sp7j.7b08g/output.s -x c++ <source>
-faddrsig
1. <eof> parser at end of file
2. Per-file LLVM IR generation
3. <source>:4:14: Generating code for declaration
'Outer<int>::Inner<0>::method'
#0 0x00005644903bf0fa llvm::sys::PrintStackTrace(llvm::raw_ostream&)
(/opt/compiler-explorer/clang-trunk-20181127/bin/clang-8+0x23a30fa)
#1 0x00005644903bd664 llvm::sys::RunSignalHandlers()
(/opt/compiler-explorer/clang-trunk-20181127/bin/clang-8+0x23a1664)
#2 0x00005644903bd7a2 SignalHandler(int)
(/opt/compiler-explorer/clang-trunk-20181127/bin/clang-8+0x23a17a2)
#3 0x00007f08b60fd890 __restore_rt
(/lib/x86_64-linux-gnu/libpthread.so.0+0x12890)
#4 0x00005644905ce531
clang::CodeGen::CGDebugInfo::getTypeOrNull(clang::QualType)
(/opt/compiler-explorer/clang-trunk-20181127/bin/clang-8+0x25b2531)
#5 0x00005644905d4cd9
clang::CodeGen::CGDebugInfo::getOrCreateType(clang::QualType, llvm::DIFile*)
(/opt/compiler-explorer/clang-trunk-20181127/bin/clang-8+0x25b8cd9)
#6 0x00005644905d4d16
clang::CodeGen::CGDebugInfo::getOrCreateType(clang::QualType, llvm::DIFile*)
(/opt/compiler-explorer/clang-trunk-20181127/bin/clang-8+0x25b8d16)
...
#253 0x00005644905d4d16
clang::CodeGen::CGDebugInfo::getOrCreateType(clang::QualType, llvm::DIFile*)
(/opt/compiler-explorer/clang-trunk-20181127/bin/clang-8+0x25b8d16)
#254 0x00005644905d4d16
clang::CodeGen::CGDebugInfo::getOrCreateType(clang::QualType, llvm::DIFile*)
(/opt/compiler-explorer/clang-trunk-20181127/bin/clang-8+0x25b8d16)
#255 0x00005644905d4d16
clang::CodeGen::CGDebugInfo::getOrCreateType(clang::QualType, llvm::DIFile*)
(/opt/compiler-explorer/clang-trunk-20181127/bin/clang-8+0x25b8d16)
clang-8: error: unable to execute command: Segmentation fault (core dumped)
clang-8: error: clang frontend command failed due to signal (use -v to see
invocation)
clang version 8.0.0 (trunk 347620) (llvm/trunk 347619)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/compiler-explorer/clang-trunk/bin
The stack trace is different if I change "delete static_cast<T*>(p);" to
"T();":
Stack dump:
0. Program arguments:
/opt/compiler-explorer/clang-trunk-20181127/bin/clang-8 -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 -mdisable-fp-elim -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
/tmp/compiler-explorer-compiler1181028-56-1424jqr.nsd4l/output.gcno
-resource-dir /opt/compiler-explorer/clang-trunk-20181127/lib/clang/8.0.0
-internal-isystem
/opt/compiler-explorer/gcc-8.2.0/lib/gcc/x86_64-linux-gnu/8.2.0/../../../../include/c++/8.2.0
-internal-isystem
/opt/compiler-explorer/gcc-8.2.0/lib/gcc/x86_64-linux-gnu/8.2.0/../../../../include/c++/8.2.0/x86_64-linux-gnu
-internal-isystem
/opt/compiler-explorer/gcc-8.2.0/lib/gcc/x86_64-linux-gnu/8.2.0/../../../../include/c++/8.2.0/backward
-internal-isystem /usr/local/include -internal-isystem
/opt/compiler-explorer/clang-trunk-20181127/lib/clang/8.0.0/include
-internal-externc-isystem /usr/include/x86_64-linux-gnu
-internal-externc-isystem /include -internal-externc-isystem /usr/include
-fdeprecated-macro -fdebug-compilation-dir
/tmp/compiler-explorer-compiler1181028-56-1424jqr.nsd4l -ferror-limit 19
-fmessage-length 0 -fobjc-runtime=gcc -fcxx-exceptions -fexceptions
-fdiagnostics-show-option -fcolor-diagnostics -o
/tmp/compiler-explorer-compiler1181028-56-1424jqr.nsd4l/output.s -x c++
<source> -faddrsig
1. <eof> parser at end of file
2. Per-file LLVM IR generation
3. <source>:4:14: Generating code for declaration
'Outer<int>::Inner<0>::method'
#0 0x0000563a2bd3a0fa llvm::sys::PrintStackTrace(llvm::raw_ostream&)
(/opt/compiler-explorer/clang-trunk-20181127/bin/clang-8+0x23a30fa)
#1 0x0000563a2bd38664 llvm::sys::RunSignalHandlers()
(/opt/compiler-explorer/clang-trunk-20181127/bin/clang-8+0x23a1664)
#2 0x0000563a2bd387a2 SignalHandler(int)
(/opt/compiler-explorer/clang-trunk-20181127/bin/clang-8+0x23a17a2)
#3 0x00007effd2dfe890 __restore_rt
(/lib/x86_64-linux-gnu/libpthread.so.0+0x12890)
#4 0x0000563a2bfb20f0 clang::CodeGen::CodeGenFunction::EmitReturnBlock()
(/opt/compiler-explorer/clang-trunk-20181127/bin/clang-8+0x261b0f0)
#5 0x0000563a2c15c20e clang::CodeGen::CodeGenFunction::EmitAnyExpr(clang::Expr
const*, clang::CodeGen::AggValueSlot, bool)
(/opt/compiler-explorer/clang-trunk-20181127/bin/clang-8+0x27c520e)
#6 0x0000563a2c16c83e
clang::CodeGen::CodeGenFunction::EmitIgnoredExpr(clang::Expr const*)
(/opt/compiler-explorer/clang-trunk-20181127/bin/clang-8+0x27d583e)
#7 0x0000563a2bf7c173 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt
const*, llvm::ArrayRef<clang::Attr const*>)
(/opt/compiler-explorer/clang-trunk-20181127/bin/clang-8+0x25e5173)
#8 0x0000563a2bf7c6f3
clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt
const&, bool, clang::CodeGen::AggValueSlot)
(/opt/compiler-explorer/clang-trunk-20181127/bin/clang-8+0x25e56f3)
#9 0x0000563a2bfb6e81
clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::CodeGen::FunctionArgList&,
clang::Stmt const*)
(/opt/compiler-explorer/clang-trunk-20181127/bin/clang-8+0x261fe81)
#10 0x0000563a2bfbf831
clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl,
llvm::Function*, clang::CodeGen::CGFunctionInfo const&)
(/opt/compiler-explorer/clang-trunk-20181127/bin/clang-8+0x2628831)
#11 0x0000563a2c013209
clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl,
llvm::GlobalValue*)
(/opt/compiler-explorer/clang-trunk-20181127/bin/clang-8+0x267c209)
#12 0x0000563a2c00fc1d
clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl,
llvm::GlobalValue*)
(/opt/compiler-explorer/clang-trunk-20181127/bin/clang-8+0x2678c1d)
#13 0x0000563a2c015e8a clang::CodeGen::CodeGenModule::EmitDeferred()
(/opt/compiler-explorer/clang-trunk-20181127/bin/clang-8+0x267ee8a)
#14 0x0000563a2c015eec clang::CodeGen::CodeGenModule::EmitDeferred()
(/opt/compiler-explorer/clang-trunk-20181127/bin/clang-8+0x267eeec)
#15 0x0000563a2c015eec clang::CodeGen::CodeGenModule::EmitDeferred()
(/opt/compiler-explorer/clang-trunk-20181127/bin/clang-8+0x267eeec)
#16 0x0000563a2c015f64 clang::CodeGen::CodeGenModule::Release()
(/opt/compiler-explorer/clang-trunk-20181127/bin/clang-8+0x267ef64)
#17 0x0000563a2c860907 (anonymous
namespace)::CodeGeneratorImpl::HandleTranslationUnit(clang::ASTContext&)
(/opt/compiler-explorer/clang-trunk-20181127/bin/clang-8+0x2ec9907)
#18 0x0000563a2c85f155
clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&)
(/opt/compiler-explorer/clang-trunk-20181127/bin/clang-8+0x2ec8155)
#19 0x0000563a2cfdfc99 clang::ParseAST(clang::Sema&, bool, bool)
(/opt/compiler-explorer/clang-trunk-20181127/bin/clang-8+0x3648c99)
#20 0x0000563a2c85e517 clang::CodeGenAction::ExecuteAction()
(/opt/compiler-explorer/clang-trunk-20181127/bin/clang-8+0x2ec7517)
#21 0x0000563a2c3c05a6 clang::FrontendAction::Execute()
(/opt/compiler-explorer/clang-trunk-20181127/bin/clang-8+0x2a295a6)
#22 0x0000563a2c384b9c
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&)
(/opt/compiler-explorer/clang-trunk-20181127/bin/clang-8+0x29edb9c)
#23 0x0000563a2c47d04b
clang::ExecuteCompilerInvocation(clang::CompilerInstance*)
(/opt/compiler-explorer/clang-trunk-20181127/bin/clang-8+0x2ae604b)
#24 0x0000563a2a45b678 cc1_main(llvm::ArrayRef<char const*>, char const*,
void*) (/opt/compiler-explorer/clang-trunk-20181127/bin/clang-8+0xac4678)
#25 0x0000563a2a3adda9 main
(/opt/compiler-explorer/clang-trunk-20181127/bin/clang-8+0xa16da9)
#26 0x00007effd1cb7b97 __libc_start_main
(/lib/x86_64-linux-gnu/libc.so.6+0x21b97)
#27 0x0000563a2a45890a _start
(/opt/compiler-explorer/clang-trunk-20181127/bin/clang-8+0xac190a)
clang-8: error: unable to execute command: Segmentation fault (core dumped)
clang-8: error: clang frontend command failed due to signal (use -v to see
invocation)
clang version 8.0.0 (trunk 347620) (llvm/trunk 347619)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/compiler-explorer/clang-trunk/bin
This issue was reported to the Android NDK bug tracker:
<a href="https://github.com/android-ndk/ndk/issues/848">https://github.com/android-ndk/ndk/issues/848</a></pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>