[llvm-bugs] [Bug 34960] New: Segfault on parsing managed C++: Crash in clang::Decl::setInvalidDecl(bool) () from libclangAST.so

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Oct 16 00:26:26 PDT 2017


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

            Bug ID: 34960
           Summary: Segfault on parsing managed C++: Crash in
                    clang::Decl::setInvalidDecl(bool) () from
                    libclangAST.so
           Product: clang
           Version: 5.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: libclang
          Assignee: unassignedclangbugs at nondot.org
          Reporter: kfunk at kde.org
                CC: klimek at google.com, llvm-bugs at lists.llvm.org

Downstream bug report:
  https://bugs.kde.org/show_bug.cgi?id=385768

In KDevelop we have a command-line utility which internally invokes libclang to
parse files in a project. For some reason, we can trigger a crash using this
utility, but I can't reproduce this crash with either clang, c-index-test or
similar utilities.


# Minimal working example

% cat ~/test.cpp                                                                
#include "test.h"
% cat ~/test.h                                                                  
#pragma once

[Serializable]
public ref class NeptuneException : Exception
{
};


# KDevelop command to produce the crash:

KDEV_CLANG_DISPLAY_ARGS=1
~/devel/build/kf5/kdevelop/kdevplatform/util/duchainify/duchainify ~/test.cpp   
Added 1 files to the background parser
parsing with 4 threads
Invocation: clang -ferror-limit=100 -fspell-checking -Wdocumentation
-Wunused-parameter -Wunreachable-code -Wall -std=c++11 -nostdinc -nostdinc++
-xc++ -isystem/usr/include/c++/6 -isystem/usr/include/x86_64-linux-gnu/c++/6
-isystem/usr/include/c++/6/backward -isystem/usr/local/include
-isystem/home/kfunk/devel/build/llvm/lib/clang/5.0.1/include
-isystem/usr/include/x86_64-linux-gnu -isystem/usr/include -imacros
/tmp/duchainify.J29089 /home/kfunk/test.cpp
libclang: crash detected during parsing: {
  'source_filename' : '/home/kfunk/test.cpp'
  'command_line_args' : ['clang', '-ferror-limit=100', '-fspell-checking',
'-Wdocumentation', '-Wunused-parameter', '-Wunreachable-code', '-Wall',
'-std=c++11', '-nostdinc', '-nostdinc++', '-xc++',
'-isystem/usr/include/c++/6', '-isystem/usr/include/x86_64-linux-gnu/c++/6',
'-isystem/usr/include/c++/6/backward', '-isystem/usr/local/include',
'-isystem/home/kfunk/devel/build/llvm/lib/clang/5.0.1/include',
'-isystem/usr/include/x86_64-linux-gnu', '-isystem/usr/include', '-imacros',
'/tmp/duchainify.J29089'],
  'unsaved_files' : [],
  'options' : 781,
}
zsh: segmentation fault  KDEV_CLANG_DISPLAY_ARGS=1  ~/test.cpp


# Clang itself does unfortunately not crash:

% clang -ferror-limit=100 -fspell-checking -Wdocumentation -Wunused-parameter
-Wunreachable-code -Wall -std=c++11 -nostdinc -nostdinc++ -xc++
-isystem/usr/include/c++/6 -isystem/usr/include/x86_64-linux-gnu/c++/6
-isystem/usr/include/c++/6/backward -isystem/usr/local/include
-isystem/home/kfunk/devel/build/llvm/lib/clang/5.0.1/include
-isystem/usr/include/x86_64-linux-gnu -isystem/usr/include -imacros
/tmp/duchainify.J20863 /home/kfunk/test.cpp
In file included from /home/kfunk/test.cpp:1:
/home/kfunk/test.h:3:1: warning: decomposition declarations are a C++17
extension [-Wc++17-extensions]
[Serializable]
^~~~~~~~~~~~~~
/home/kfunk/test.h:3:1: error: C++ requires a type specifier for all
declarations
/home/kfunk/test.h:3:1: error: decomposition declaration cannot be declared
with type 'int'; declared type must be 'auto' or reference to 'auto'
/home/kfunk/test.h:3:1: error: decomposition declaration '[Serializable]'
requires an initializer
/home/kfunk/test.h:3:15: error: expected ';' after top level declarator
[Serializable]
              ^
              ;                                                                 
1 warning and 4 errors generated.


# Detailed backtrace with current Clang/LLVM 5.0 branch:

Backtrace with a LLVM debug build (LLVM 5.0 branch):
#0  0x00007fffc52a8f5b in clang::Decl::setInvalidDecl (this=0x0, Invalid=true)
at /home/kfunk/devel/src/llvm/tools/clang/lib/AST/DeclBase.cpp:112
#1  0x00007fffc52a8fad in clang::Decl::setInvalidDecl (this=<optimized out>,
Invalid=<optimized out>) at
/home/kfunk/devel/src/llvm/tools/clang/lib/AST/DeclBase.cpp:129
#2  0x00007fffbb7020aa in clang::ASTDeclReader::VisitDecl (this=0x7fffaa7fb0b0,
D=0x7fff94029eb8) at
/home/kfunk/devel/src/llvm/tools/clang/lib/Serialization/ASTReaderDecl.cpp:537
#3  0x00007fffbb703da6 in clang::ASTDeclReader::VisitNamedDecl
(this=0x7fffaa7fb0b0, ND=0x7fff94029eb8) at
/home/kfunk/devel/src/llvm/tools/clang/lib/Serialization/ASTReaderDecl.cpp:609
#4  clang::ASTDeclReader::VisitValueDecl (this=0x7fffaa7fb0b0,
VD=0x7fff94029eb8) at
/home/kfunk/devel/src/llvm/tools/clang/lib/Serialization/ASTReaderDecl.cpp:746
#5  clang::ASTDeclReader::VisitDeclaratorDecl (this=0x7fffaa7fb0b0,
DD=0x7fff94029eb8) at
/home/kfunk/devel/src/llvm/tools/clang/lib/Serialization/ASTReaderDecl.cpp:759
#6  0x00007fffbb70863b in clang::ASTDeclReader::VisitVarDeclImpl
(this=0x7fffaa7fb0b0, VD=0x7fff94029eb8) at
/home/kfunk/devel/src/llvm/tools/clang/lib/Serialization/ASTReaderDecl.cpp:1260
#7  0x00007fffbb701db5 in clang::ASTDeclReader::VisitVarDecl
(this=0x7fffaa7fb0b0, VD=0x7fff94029eb8) at
/home/kfunk/devel/src/llvm/tools/clang/lib/Serialization/ASTReaderDecl.cpp:333
#8  clang::ASTDeclReader::VisitDecompositionDecl (this=0x7fffaa7fb0b0,
DD=0x7fff94029eb8) at
/home/kfunk/devel/src/llvm/tools/clang/lib/Serialization/ASTReaderDecl.cpp:1352
#9  clang::declvisitor::Base<clang::declvisitor::make_ptr,
clang::ASTDeclReader, void>::Visit (this=0x7fffaa7fb0b0, D=0x7fff94029eb8) at
tools/clang/include/clang/AST/DeclNodes.inc:445
#10 0x00007fffbb701332 in clang::ASTDeclReader::Visit (this=0x7fffaa7fb0b0,
D=0x7fff94029eb8) at
/home/kfunk/devel/src/llvm/tools/clang/lib/Serialization/ASTReaderDecl.cpp:468
#11 0x00007fffbb7276e1 in clang::ASTReader::ReadDeclRecord
(this=0x7fff9406b030, ID=19) at
/home/kfunk/devel/src/llvm/tools/clang/lib/Serialization/ASTReaderDecl.cpp:3623
#12 0x00007fffbb6c5d7d in clang::ASTReader::GetDecl (this=0x7fff9406b030,
ID=19) at
/home/kfunk/devel/src/llvm/tools/clang/lib/Serialization/ASTReader.cpp:7102
#13 0x00007fffbb727ccb in clang::ASTReader::PassInterestingDeclsToConsumer
(this=0x7fff9406b030) at
/home/kfunk/devel/src/llvm/tools/clang/lib/Serialization/ASTReaderDecl.cpp:3674
#14 0x00007fffbb6dbefc in non-virtual thunk to
clang::ASTReader::StartTranslationUnit(clang::ASTConsumer*) () at
/home/kfunk/devel/src/llvm/tools/clang/lib/Serialization/ASTReader.cpp:7356
#15 0x00007fffbb821328 in clang::ParseAST (S=..., PrintStats=<optimized out>,
SkipFunctionBodies=<optimized out>) at
/home/kfunk/devel/src/llvm/tools/clang/lib/Parse/ParseAST.cpp:144

-- 
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/20171016/fad2385c/attachment-0001.html>


More information about the llvm-bugs mailing list