[llvm-bugs] [Bug 39817] New: crash on explicit specialization inside a template class definition

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Nov 27 21:19:51 PST 2018


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

            Bug ID: 39817
           Summary: crash on explicit specialization inside a template
                    class definition
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Frontend
          Assignee: unassignedclangbugs at nondot.org
          Reporter: rprichard at google.com
                CC: llvm-bugs at lists.llvm.org, neeilans at live.com,
                    richard-llvm at metafoo.co.uk

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:
http://open-std.org/JTC1/SC22/WG21/docs/cwg_defects.html#727

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:
https://github.com/android-ndk/ndk/issues/848

-- 
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/20181128/6153b121/attachment-0001.html>


More information about the llvm-bugs mailing list