<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 - Segfault on parsing managed C++: Crash in clang::Decl::setInvalidDecl(bool) () from libclangAST.so"
href="https://bugs.llvm.org/show_bug.cgi?id=34960">34960</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Segfault on parsing managed C++: Crash in clang::Decl::setInvalidDecl(bool) () from libclangAST.so
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>5.0
</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>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>libclang
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>kfunk@kde.org
</td>
</tr>
<tr>
<th>CC</th>
<td>klimek@google.com, llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>Downstream bug report:
<a href="https://bugs.kde.org/show_bug.cgi?id=385768">https://bugs.kde.org/show_bug.cgi?id=385768</a>
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</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>