Bug 376084 - Crash on code parsing
Summary: Crash on code parsing
Status: RESOLVED UPSTREAM
Alias: None
Product: kdevelop
Classification: Applications
Component: Language Support: CPP (Clang-based) (show other bugs)
Version: git master
Platform: Other Linux
: NOR crash
Target Milestone: ---
Assignee: kdevelop-bugs-null
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-02-06 02:15 UTC by Roman
Modified: 2017-04-12 20:38 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Roman 2017-02-06 02:15:43 UTC
template<typename T> using crash = struct : public virtual T {}


I tested this for:

latest appImage, gentoo live build with clang3.9/4.0.
Comment 1 Francis Herne 2017-04-11 13:58:28 UTC
Reproducible with 5.1.0 and Clang 3.9.1 - when opening a document containing only that line, KDevelop crashes immediately with the backtrace below.

-----------

Thread 138 "Queue(0x6040004" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fffb0fd1700 (LWP 9119)]
0x00007fffb71f04c4 in ?? () from /usr/lib/libclang.so.3.9
(gdb) bt
#0  0x00007fffb71f04c4 in  () at /usr/lib/libclang.so.3.9
#1  0x00007fffb71f0ac5 in  () at /usr/lib/libclang.so.3.9
#2  0x00007fffb711b8c2 in  () at /usr/lib/libclang.so.3.9
#3  0x00007fffb71130bf in  () at /usr/lib/libclang.so.3.9
#4  0x00007fffb71132a5 in  () at /usr/lib/libclang.so.3.9
#5  0x00007fffb7113350 in  () at /usr/lib/libclang.so.3.9
#6  0x00007fffb7113369 in  () at /usr/lib/libclang.so.3.9
#7  0x00007fffb70e605b in clang_Type_getSizeOf () at /usr/lib/libclang.so.3.9
#8  0x00007fffb89d82cd in (anonymous namespace)::Visitor::setDeclData<(CXCursorKind)2, (detail::enabler)0>(CXCursor, KDevelop::ClassDeclaration*) const (this=<optimized out>, cursor=..., decl=<optimized out>) at /home/flh/projects/kdevelop/languages/clang/duchain/builder.cpp:1044
#9  0x00007fffb89d5e7d in (anonymous namespace)::Visitor::createDeclarationCommon<(CXCursorKind)2, KDevelop::ClassDeclaration>(CXCursor, KDevelop::Identifier const&) (this=0x7fffb0fcf8c0, id=..., cursor=...) at /home/flh/projects/kdevelop/languages/clang/duchain/builder.cpp:396
#10 0x00007fffb89d5e7d in (anonymous namespace)::Visitor::createDeclaration<(CXCursorKind)2, KDevelop::ClassDeclaration>(CXCursor, KDevelop::Identifier const&, KDevelop::DUContext*) (this=<optimized out>, cursor=..., id=..., context=<optimized out>) at /home/flh/projects/kdevelop/languages/clang/duchain/builder.cpp:407
#11 0x00007fffb89d5e7d in (anonymous namespace)::Visitor::buildDeclaration<(CXCursorKind)2, KDevelop::ClassDeclaration, true>(CXCursor) (this=<optimized out>, cursor=...)
    at /home/flh/projects/kdevelop/languages/clang/duchain/builder.cpp:1144
#12 0x00007fffb89b7bbc in (anonymous namespace)::Visitor::dispatchCursor<(CXCursorKind)2, (Decision)0, (Decision)0, (detail::enabler)0>(CXCursor, CXCursor) (this=<optimized out>, cursor=..., parent=...) at /home/flh/projects/kdevelop/languages/clang/duchain/builder.cpp:907
#13 0x00007fffb89b7bbc in (anonymous namespace)::Visitor::dispatchCursor<(CXCursorKind)2, (Decision)0, (Decision)2, (detail::enabler)0>(CXCursor, CXCursor) (this=<optimized out>, cursor=..., parent=...) at /home/flh/projects/kdevelop/languages/clang/duchain/builder.cpp:882
#14 0x00007fffb89b7bbc in (anonymous namespace)::Visitor::dispatchCursor<(CXCursorKind)2, (Decision)2, (detail::enabler)0>(CXCursor, CXCursor) (this=<optimized out>, cursor=..., parent=...)
    at /home/flh/projects/kdevelop/languages/clang/duchain/builder.cpp:870
#15 0x00007fffb89b7bbc in (anonymous namespace)::visitCursor(CXCursor, CXCursor, void*) (cursor=..., parent=..., data=0x7fffb0fcf8c0)
    at /home/flh/projects/kdevelop/languages/clang/duchain/builder.cpp:1452
#16 0x00007fffb70acf15 in  () at /usr/lib/libclang.so.3.9
#17 0x00007fffb70ac45d in  () at /usr/lib/libclang.so.3.9
#18 0x00007fffb70ac582 in  () at /usr/lib/libclang.so.3.9
#19 0x00007fffb70acbac in  () at /usr/lib/libclang.so.3.9
#20 0x00007fffb70b5704 in clang_visitChildren () at /usr/lib/libclang.so.3.9
#21 0x00007fffb89abc5b in (anonymous namespace)::Visitor::Visitor(CXTranslationUnitImpl*, void*, QHash<void*, KDevelop::ReferencedTopDUContext> const&, bool) (this=<optimized out>, tu=0x7fffb0fcf4c0, file=<optimized out>, includes=..., update=<optimized out>) at /home/flh/projects/kdevelop/languages/clang/duchain/builder.cpp:1378
#22 0x00007fffb89abc5b in Builder::visit(CXTranslationUnitImpl*, void*, QHash<void*, KDevelop::ReferencedTopDUContext> const&, bool) (tu=<optimized out>, file=<optimized out>, includes=..., update=<optimized out>) at /home/flh/projects/kdevelop/languages/clang/duchain/builder.cpp:1515
#23 0x00007fffb8a795c7 in ClangHelpers::buildDUChain(void*, QMultiHash<void*, Import> const&, ParseSession const&, KDevelop::TopDUContext::Features, QHash<void*, KDevelop::ReferencedTopDUContext>&, ClangIndex*, std::function<bool ()> const&) (file=0x0, imports=..., session=..., features=-24613, includedFiles=..., index=<optimized out>, abortFunction=...)
    at /home/flh/projects/kdevelop/languages/clang/duchain/clanghelpers.cpp:189
#24 0x00007fffb9012640 in ClangParseJob::run(QSharedPointer<ThreadWeaver::JobInterface>, ThreadWeaver::Thread*) (this=0x60c000e6ac40)
    at /home/flh/projects/kdevelop/languages/clang/clangparsejob.cpp:321
#25 0x00007fffb901540d in non-virtual thunk to ClangParseJob::run(QSharedPointer<ThreadWeaver::JobInterface>, ThreadWeaver::Thread*) ()
    at /home/flh/projects/kdevelop/languages/clang/clangparsejob.cpp:219
#26 0x00007fffea2c05d6 in ThreadWeaver::IdDecorator::run(QSharedPointer<ThreadWeaver::JobInterface>, ThreadWeaver::Thread*) () at /usr/lib/libKF5ThreadWeaver.so.5
#27 0x00007fffea2c0bd8 in ThreadWeaver::Executor::run(QSharedPointer<ThreadWeaver::JobInterface> const&, ThreadWeaver::Thread*) () at /usr/lib/libKF5ThreadWeaver.so.5
#28 0x00007fffea2bfaea in ThreadWeaver::Job::execute(QSharedPointer<ThreadWeaver::JobInterface> const&, ThreadWeaver::Thread*) () at /usr/lib/libKF5ThreadWeaver.so.5
#29 0x00007fffea2bf190 in ThreadWeaver::Thread::run() () at /usr/lib/libKF5ThreadWeaver.so.5
#30 0x00007fffefdad6d8 in  () at /usr/lib/libQt5Core.so.5
#31 0x00007fffef44e2e7 in start_thread () at /usr/lib/libpthread.so.0
#32 0x00007fffeeb6c54f in clone () at /usr/lib/libc.so.6
Comment 2 Boris Egorov 2017-04-12 10:29:38 UTC
I've made a backtrace with Clang debugging symbols, hope it will help. I wanted to dig a bit further, but gdb hangs completely.

------
template<typename T> using crash = struct : public virtual T {}
(gdb) bt
#0  0x00007fffb084d5da in clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (this=0x7fff3c0c1e20, D=D@entry=0x0)
    at /usr/src/debug/cfe-3.9.1.src/lib/AST/RecordLayoutBuilder.cpp:2929
#1  0x00007fffb084dcc4 in (anonymous namespace)::EmptySubobjectMap::ComputeEmptySubobjectSizes (this=0x7fff8affacf0)
    at /usr/src/debug/cfe-3.9.1.src/lib/AST/RecordLayoutBuilder.cpp:192
#2  0x00007fffb084dcc4 in (anonymous namespace)::EmptySubobjectMap::EmptySubobjectMap (Class=0x7fff3c1504f0, Context=..., this=0x7fff8affacf0)
    at /usr/src/debug/cfe-3.9.1.src/lib/AST/RecordLayoutBuilder.cpp:171
#3  0x00007fffb084dcc4 in clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (this=this@entry=0x7fff3c0c1e20, D=<optimized out>,
    D@entry=0x7fff3c1504f0) at /usr/src/debug/cfe-3.9.1.src/lib/AST/RecordLayoutBuilder.cpp:2965
#4  0x00007fffb06f7c02 in clang::ASTContext::getTypeInfoImpl(clang::Type const*) const (this=this@entry=0x7fff3c0c1e20, T=0x7fff3c150590)
    at /usr/src/debug/cfe-3.9.1.src/lib/AST/ASTContext.cpp:1769
#5  0x00007fffb06eed0c in clang::ASTContext::getTypeInfo(clang::Type const*) const (this=this@entry=0x7fff3c0c1e20, T=<optimized out>,
    T@entry=0x7fff3c150590) at /usr/src/debug/cfe-3.9.1.src/lib/AST/ASTContext.cpp:1513
#6  0x00007fffb06eef85 in clang::ASTContext::getTypeInfoInChars(clang::Type const*) const (this=0x7fff3c0c1e20, T=0x7fff3c150590)
    at /usr/src/debug/cfe-3.9.1.src/lib/AST/ASTContext.cpp:1489
#7  0x00007fffb06ef030 in clang::ASTContext::getTypeInfoInChars(clang::QualType) const (this=this@entry=0x7fff3c0c1e20, T=...)
    at /usr/src/debug/cfe-3.9.1.src/lib/AST/ASTContext.cpp:1496
#8  0x00007fffb06ef0b9 in clang::ASTContext::getTypeSizeInChars(clang::QualType) const (this=this@entry=0x7fff3c0c1e20, T=..., T@entry=...)
    at /usr/src/debug/cfe-3.9.1.src/lib/AST/ASTContext.cpp:1870
#9  0x00007fffb0b7804b in clang_Type_getSizeOf(CXType) (T=...) at /usr/src/debug/cfe-3.9.1.src/tools/libclang/CXType.cpp:769
#10 0x00007fffb0df92fb in (anonymous namespace)::Visitor::setDeclData<(CXCursorKind)2>(CXCursor, KDevelop::ClassDeclaration*) const (this=this@entry=0x7fff8affc710, cursor=..., decl=decl@entry=0x7fff8000d4a0) at /usr/src/debug/kdevelop-5.1.0/languages/clang/duchain/builder.cpp:1044
#11 0x00007fffb0e144cc in (anonymous namespace)::Visitor::createDeclarationCommon<(CXCursorKind)2, KDevelop::ClassDeclaration> (id=..., cursor=..., this=0x7fff8affc710) at /usr/src/debug/kdevelop-5.1.0/languages/clang/duchain/builder.cpp:396
#12 0x00007fffb0e144cc in (anonymous namespace)::Visitor::createDeclaration<(CXCursorKind)2, KDevelop::ClassDeclaration> (context=0x7fff8000ea80, id=..., cursor=..., this=0x7fff8affc710) at /usr/src/debug/kdevelop-5.1.0/languages/clang/duchain/builder.cpp:407
#13 0x00007fffb0e144cc in (anonymous namespace)::Visitor::buildDeclaration<(CXCursorKind)2, KDevelop::ClassDeclaration, true> (cursor=..., this=0x7fff8affc710) at /usr/src/debug/kdevelop-5.1.0/languages/clang/duchain/builder.cpp:1144
#14 0x00007fffb0e144cc in (anonymous namespace)::Visitor::dispatchCursor<(CXCursorKind)2, (Decision)1, (Decision)0> (parent=..., cursor=..., this=0x7fff8affc710) at /usr/src/debug/kdevelop-5.1.0/languages/clang/duchain/builder.cpp:907
#15 0x00007fffb0e144cc in (anonymous namespace)::Visitor::dispatchCursor<(CXCursorKind)2, (Decision)1, (Decision)2>(CXCursor, CXCursor) (this=this@entry=0x7fff8affc710, cursor=..., parent=...) at /usr/src/debug/kdevelop-5.1.0/languages/clang/duchain/builder.cpp:881
#16 0x00007fffb0e1629c in (anonymous namespace)::Visitor::dispatchCursor<(CXCursorKind)2> (parent=..., cursor=..., this=0x7fff8affc710)
    at /usr/src/debug/kdevelop-5.1.0/languages/clang/duchain/builder.cpp:869
#17 0x00007fffb0e1629c in (anonymous namespace)::visitCursor(CXCursor, CXCursor, CXClientData) (cursor=..., parent=..., data=0x7fff8affc710)
    at /usr/src/debug/kdevelop-5.1.0/languages/clang/duchain/builder.cpp:1452
#18 0x00007fffb0b48fd5 in clang::cxcursor::CursorVisitor::Visit(CXCursor, bool) (this=this@entry=0x7fff8affc4a0, Cursor=..., CheckedRegionOfInterest=CheckedRegionOfInterest@entry=true) at /usr/src/debug/cfe-3.9.1.src/tools/libclang/CIndex.cpp:208
#19 0x00007fffb0b4c9bd in clang::cxcursor::CursorVisitor::handleDeclForVisitation(clang::Decl const*) (this=this@entry=0x7fff8affc4a0, D=0x7fff3c1504f0)
    at /usr/src/debug/cfe-3.9.1.src/tools/libclang/CIndex.cpp:665
#20 0x00007fffb0b4cae6 in clang::cxcursor::CursorVisitor::VisitDeclContext(clang::DeclContext*) (this=this@entry=0x7fff8affc4a0, DC=0x7fff3c0ceb60)
    at /usr/src/debug/cfe-3.9.1.src/tools/libclang/CIndex.cpp:626
#21 0x00007fffb0b48cc0 in clang::cxcursor::CursorVisitor::VisitChildren(CXCursor) (this=this@entry=0x7fff8affc4a0, Cursor=...)
    at /usr/src/debug/cfe-3.9.1.src/tools/libclang/CIndex.cpp:531
#22 0x00007fffb0b51864 in clang_visitChildren(CXCursor, CXCursorVisitor, CXClientData) (parent=..., visitor=visitor@entry=0x7fffb0e15290 <(anonymous namespace)::visitCursor(CXCursor, CXCursor, CXClientData)>, client_data=client_data@entry=0x7fff8affc710)
    at /usr/src/debug/cfe-3.9.1.src/tools/libclang/CIndex.cpp:4041
#23 0x00007fffb0e002e2 in (anonymous namespace)::Visitor::Visitor (update=<optimized out>, includes=..., file=<optimized out>, tu=<optimized out>, this=0x7fff8affc710) at /usr/src/debug/kdevelop-5.1.0/languages/clang/duchain/builder.cpp:1378
#24 0x00007fffb0e002e2 in Builder::visit(CXTranslationUnitImpl*, void*, QHash<void*, KDevelop::ReferencedTopDUContext> const&, bool) (tu=<optimized out>, file=<optimized out>, includes=..., update=<optimized out>) at /usr/src/debug/kdevelop-5.1.0/languages/clang/duchain/builder.cpp:1515
#25 0x00007fffb0e26525 in ClangHelpers::buildDUChain(void*, QMultiHash<void*, Import> const&, ParseSession const&, KDevelop::TopDUContext::Features, QHash<void*, KDevelop::ReferencedTopDUContext>&, ClangIndex*, std::function<bool ()> const&) (file=<optimized out>, imports=..., session=..., features=<optimized out>, includedFiles=..., index=0x5555564c3970, abortFunction=...) at /usr/src/debug/kdevelop-5.1.0/languages/clang/duchain/clanghelpers.cpp:189
#26 0x00007fffb1087384 in ClangParseJob::run(QSharedPointer<ThreadWeaver::JobInterface>, ThreadWeaver::Thread*) (this=<optimized out>)
    at /usr/src/debug/kdevelop-5.1.0/languages/clang/clangparsejob.cpp:323
#27 0x00007fffee783baa in ThreadWeaver::IdDecorator::run(QSharedPointer<ThreadWeaver::JobInterface>, ThreadWeaver::Thread*) ()
    at /lib64/libKF5ThreadWeaver.so.5
#28 0x00007fffee7841b8 in ThreadWeaver::Executor::run(QSharedPointer<ThreadWeaver::JobInterface> const&, ThreadWeaver::Thread*) ()
    at /lib64/libKF5ThreadWeaver.so.5
#29 0x00007fffee782d00 in ThreadWeaver::Job::execute(QSharedPointer<ThreadWeaver::JobInterface> const&, ThreadWeaver::Thread*) ()
    at /lib64/libKF5ThreadWeaver.so.5
#30 0x00007fffee782810 in ThreadWeaver::Thread::run() () at /lib64/libKF5ThreadWeaver.so.5
#31 0x00007ffff21489ca in QThreadPrivate::start(void*) () at /lib64/libQt5Core.so.5
#32 0x00007fffea5416ca in start_thread () at /lib64/libpthread.so.0
#33 0x00007ffff153bf7f in clone () at /lib64/libc.so.6
(gdb) list
2924      // These asserts test different things.  A record has a definition
2925      // as soon as we begin to parse the definition.  That definition is
2926      // not a complete definition (which is what isDefinition() tests)
2927      // until we *finish* parsing the definition.
2928
2929      if (D->hasExternalLexicalStorage() && !D->getDefinition())
2930        getExternalSource()->CompleteType(const_cast<RecordDecl*>(D));
2931
2932      D = D->getDefinition();
2933      assert(D && "Cannot get layout of forward declarations!");
(gdb) p D
$1 = (const clang::RecordDecl *) 0x0
(gdb) up
#1  0x00007fffb084dcc4 in (anonymous namespace)::EmptySubobjectMap::ComputeEmptySubobjectSizes (this=0x7fff8affacf0)
    at /usr/src/debug/cfe-3.9.1.src/lib/AST/RecordLayoutBuilder.cpp:192
192         const ASTRecordLayout &Layout = Context.getASTRecordLayout(BaseDecl);
(gdb) p BaseDecl
$2 = (const clang::CXXRecordDecl *) 0x0
(gdb) p Base
$3 = (const clang::CXXBaseSpecifier &) @0x7fff3c150638: {Range = {B = {ID = 46}, E = {ID = 61}}, EllipsisLoc = {ID = 0}, Virtual = 1, BaseOfClass = 0,
  Access = 0, InheritConstructors = 0, BaseTypeInfo = 0x7fff3c150610}
(gdb) p Base.getType()
Cannot evaluate function -- may be inlined
(gdb) p (BaseTypeInfo*)0x7fff3c150610
No symbol "BaseTypeInfo" in current context.
(gdb) p (clang::TypeSourceInfo*)0x7fff3c150610
$4 = (clang::TypeSourceInfo *) 0x7fff3c150610
(gdb) p ((clang::TypeSourceInfo*)0x7fff3c150610)->getType()
Cannot evaluate function -- may be inlined
(gdb) p *((clang::TypeSourceInfo*)0x7fff3c150610)
$5 = {Ty = {Value = {Value = 140734201398448}}}
(gdb) up
#2  (anonymous namespace)::EmptySubobjectMap::EmptySubobjectMap (Class=0x7fff3c1504f0, Context=..., this=0x7fff8affacf0)
    at /usr/src/debug/cfe-3.9.1.src/lib/AST/RecordLayoutBuilder.cpp:171
171           ComputeEmptySubobjectSizes();
(gdb) up
#3  clang::ASTContext::getASTRecordLayout (this=this@entry=0x7fff3c0c1e20, D=<optimized out>, D@entry=0x7fff3c1504f0)
    at /usr/src/debug/cfe-3.9.1.src/lib/AST/RecordLayoutBuilder.cpp:2965
2965          EmptySubobjectMap EmptySubobjects(*this, RD);
(gdb) p this
$6 = (const clang::ASTContext * const) 0x7fff3c0c1e20
(gdb)
Comment 3 Kevin Funk 2017-04-12 11:07:12 UTC
This looks like a bug in clang_Type_getSizeOf(...):

languages/clang/duchain/builder.cpp:1044:
        auto sizeOf = clang_Type_getSizeOf(type);

This is something we can potentially work-around; looks like we're trying to figure out the size of `crash`, which is an incomplete type (thus no size calculation possible).

Maybe check whether `type` is incomplete before trying to getting the size/alignment information inside duchain.cpp?
Comment 4 Kevin Funk 2017-04-12 20:38:27 UTC
Unfixable in KDevelop, I think. Reported upstream:
  https://bugs.llvm.org/show_bug.cgi?id=32643