xavierd / clang_complete

Vim plugin that use clang for completing C/C++ code.
http://www.vim.org/scripts/script.php?script_id=3302
1.95k stars 308 forks source link

libclang: crash detected in code completion when using -std=c++11 #312

Open fiesh opened 11 years ago

fiesh commented 11 years ago

Consider the following code:

#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/phoenix_core.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>

void parse()
{
    using boost::spirit::qi::lit;
    using boost::phoenix::ref;
    boost::spirit::qi::rule<std::string::iterator> z;
    bool b = true;
    z = lit("on")[ref(b) = true];
}

void test()
{
    //boost::
}

It compiles

clang++ -c -o t.o -std=c++11 t.cpp

and, uncommenting line 20, one can autocomplete it on the command line:

clang -I/usr/include -x c++ -I/usr/lib/llvm/../clang/3.2/include/ -fsyntax-only -Xclang -code-completion-at=/tmp/t.cpp:20:9 -std=c++11 /tmp/t.cpp

However, when using clang_complete (setting -std=c++11 in .clang_complete!), I get

libclang: crash detected during reparsing
libclang: crash detected in code completion

This does not happen without -std=c++11, but of course in an actual real world example I need this.

tobiasgrosser commented 11 years ago

On 04/16/2013 08:12 AM, fiesh wrote:

Consider the following code:

#include <boost/spirit/include/qi.hpp>

#include <#include <boost/spirit/include/qi.hpp>

#include <boost/spirit/include/phoenix_core.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>

void parse()
{
  using boost::spirit::qi::lit;
  using boost::phoenix::ref;

  boost::spirit::qi::rule<std::string::iterator> z;

  bool b = true;

  z = lit("on")[ref(b) = true];
}

void test()
{
  //boost::
}

It compiles

clang++ -c -o t.o -std=c++11 t.cpp

and, uncommenting line 20, one can autocomplete it on the command line:

clang -I/usr/include -x c++ -I/usr/lib/llvm/../clang/3.2/include/ -fsyntax-only -Xclang -code-completion-at=/tmp/t.cpp:20:9 -std=c++11 /tmp/t.cpp

However, when using clang_complete (setting -std=c++11 in .clang_complete!), I get

libclang: crash detected during reparsing
libclang: crash detected in code completion

This does not happen without -std=c++11, but of course in an actual real world example I need this.

Very nice bug report. I have the feeling this is a clang crash that we need to report upstream. For this it would be great to really make this a minimal test case.

Could you try if you can preprocess the source code and make this a single source file that can possibly further reduced. If preprocessing does not work, it would still be nice to reduce the include files as much as possible, too.

Tobi

fiesh commented 11 years ago

I will do when I find the time, sorry, might be a little bit!

bmerry commented 10 years ago

It's not just code completion: if I create the same file, up to the end of the parse() function, and run g:ClangUpdateQuickFix(), it also crashes. I built Debug+Asserts version of clang from svn (r195230) and ran it in gdb, and it hits a null pointer assert. The backtrace (first few and last few frames - I didn't try to paste all 158 function calls) is below - hope it helps. If I continue in gdb, I get this output and a SIGABRT - I haven't pasted that backtrace but I can if it is useful:

libclang: crash detected during reparsing
gvim: /home/bmerry/src/llvm/tools/clang/lib/Frontend/ASTUnit.cpp:2947: void clang::ASTUnit::ConcurrencyState::start(): Assertion `acquired && "Concurrent access to ASTUnit!"' failed.
#0  0x00007ffff3c23f77 in __GI_raise (sig=sig@entry=6)
    at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
#1  0x00007ffff3c275e8 in __GI_abort () at abort.c:90
#2  0x00007ffff3c1cd43 in __assert_fail_base (
    fmt=0x7ffff3d73f58 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", 
    assertion=assertion@entry=0x7fffcb6c78f7 "!isNull() && \"Cannot retrieve a NULL type pointer\"", 
    file=file@entry=0x7fffcb6c792a "/home/bmerry/src/llvm/tools/clang/tools/libclang/../../include/clang/AST/Type.h", line=line@entry=547, 
    function=function@entry=0x7fffcb6c797a "const clang::ExtQualsTypeCommonBase *clang::QualType::getCommonPtr() const") at assert.c:92
#3  0x00007ffff3c1cdf2 in __GI___assert_fail (
    assertion=0x7fffcb6c78f7 "!isNull() && \"Cannot retrieve a NULL type pointer\"", 
    file=0x7fffcb6c792a "/home/bmerry/src/llvm/tools/clang/tools/libclang/../../include/clang/AST/Type.h", line=547, 
    function=0x7fffcb6c797a "const clang::ExtQualsTypeCommonBase *clang::QualType::getCommonPtr() const") at assert.c:101
#4  0x00007fffca37b1f5 in clang::QualType::getCommonPtr (this=0x7fffc68e5dd8)
    at /home/bmerry/src/llvm/tools/clang/tools/libclang/../../include/clang/AST/Type.h:547
#5  0x00007fffca3d63a9 in clang::QualType::getCanonicalType (
    this=0x7fffc68e5dd8)
    at /home/bmerry/src/llvm/tools/clang/tools/libclang/../../include/clang/AST/Type.h:4671
#6  0x00007fffca3d32bc in clang::ASTContext::getCanonicalType (
    this=0x7fffad654660, T=...)
    at /home/bmerry/src/llvm/tools/clang/tools/libclang/../../include/clang/AST/ASTContext.h:1736
#7  0x00007fffcb561fdb in (anonymous namespace)::StmtProfiler::VisitType (
    this=0x7fffc68e6138, T=...)
    at /home/bmerry/src/llvm/tools/clang/lib/AST/StmtProfile.cpp:1208
#8  0x00007fffcb561da5 in (anonymous namespace)::StmtProfiler::VisitDecl (
    this=0x7fffc68e6138, D=0x7fffba76c230)
    at /home/bmerry/src/llvm/tools/clang/lib/AST/StmtProfile.cpp:1180
#9  0x00007fffcb55fd87 in (anonymous namespace)::StmtProfiler::VisitDeclRefExpr (this=0x7fffc68e6138, S=0x7fffba76c330)
    at /home/bmerry/src/llvm/tools/clang/lib/AST/StmtProfile.cpp:309
#10 0x00007fffcb55d421 in clang::StmtVisitorBase<clang::make_const_ptr, (anonymous namespace)::StmtProfiler, void>::Visit (this=0x7fffc68e6138, 
    S=0x7fffba76c330)
    at /home/bmerry/src/llvm/build/tools/clang/lib/AST/../../include/clang/AST/StmtNodes.inc:427
#11 0x00007fffcb561c0b in (anonymous namespace)::StmtProfiler::VisitStmt (
    this=0x7fffc68e6138, S=0x7fffba76c358)
    at /home/bmerry/src/llvm/tools/clang/lib/AST/StmtProfile.cpp:74
#12 0x00007fffcb56249d in (anonymous namespace)::StmtProfiler::VisitExpr (
    this=0x7fffc68e6138, S=0x7fffba76c358)
    at /home/bmerry/src/llvm/tools/clang/lib/AST/StmtProfile.cpp:302
#13 0x00007fffcb55f7cd in (anonymous namespace)::StmtProfiler::VisitCallExpr (
    this=0x7fffc68e6138, S=0x7fffba76c358)
    at /home/bmerry/src/llvm/tools/clang/lib/AST/StmtProfile.cpp:400
#14 0x00007fffcb55d289 in clang::StmtVisitorBase<clang::make_const_ptr, (anonymous namespace)::StmtProfiler, void>::Visit (this=0x7fffc68e6138, 
    S=0x7fffba76c358)
    at /home/bmerry/src/llvm/build/tools/clang/lib/AST/../../include/clang/AST/StmtNodes.inc:299
#15 0x00007fffcb55c8ee in clang::Stmt::Profile (this=0x7fffba76c358, ID=..., 
    Context=..., Canonical=true)
    at /home/bmerry/src/llvm/tools/clang/lib/AST/StmtProfile.cpp:1281
#16 0x00007fffcb577175 in clang::DependentDecltypeType::Profile (ID=..., 
    Context=..., E=0x7fffba76c358)
    at /home/bmerry/src/llvm/tools/clang/lib/AST/Type.cpp:1811
#17 0x00007fffcb34df9b in clang::ASTContext::getDecltypeType (
    this=0x7fffad654660, e=0x7fffba76c358, UnderlyingType=...)
    at /home/bmerry/src/llvm/tools/clang/lib/AST/ASTContext.cpp:3683
#18 0x00007fffca6263e3 in clang::ASTReader::readTypeRecord (
    this=0x7fffb9686630, Index=259916)
    at /home/bmerry/src/llvm/tools/clang/lib/Serialization/ASTReader.cpp:4727
#19 0x00007fffca621a8e in clang::ASTReader::GetType (this=0x7fffb9686630, 
    ID=2080128)
    at /home/bmerry/src/llvm/tools/clang/lib/Serialization/ASTReader.cpp:5278
#20 0x00007fffca62a810 in clang::ASTReader::getLocalType (
    this=0x7fffb9686630, F=..., LocalID=2080128)
    at /home/bmerry/src/llvm/tools/clang/lib/Serialization/ASTReader.cpp:5292
#21 0x00007fffca63be0b in clang::ASTReader::readType (this=0x7fffb9686630, 
    F=..., Record=..., Idx=@0x7fffc68e7f74: 1)
    at /home/bmerry/src/llvm/tools/clang/lib/Serialization/../../include/clang/Serialization/ASTReader.h:1432
#22 0x00007fffca625b8d in clang::ASTReader::readTypeRecord (
    this=0x7fffb9686630, Index=246733)
    at /home/bmerry/src/llvm/tools/clang/lib/Serialization/ASTReader.cpp:4655
#23 0x00007fffca621a8e in clang::ASTReader::GetType (this=0x7fffb9686630, 
    ID=1974664)
    at /home/bmerry/src/llvm/tools/clang/lib/Serialization/ASTReader.cpp:5278
#24 0x00007fffca62a810 in clang::ASTReader::getLocalType (
    this=0x7fffb9686630, F=..., LocalID=1974664)
    at /home/bmerry/src/llvm/tools/clang/lib/Serialization/ASTReader.cpp:5292
#25 0x00007fffca63be0b in clang::ASTReader::readType (this=0x7fffb9686630, 
    F=..., Record=..., Idx=@0x7fffc68e8fc0: 15)
    at /home/bmerry/src/llvm/tools/clang/lib/Serialization/../../include/clang/Serialization/ASTReader.h:1432
#26 0x00007fffca68aca8 in clang::ASTDeclReader::VisitValueDecl (
    this=0x7fffc68e8f90, VD=0x7fffba76c290)
    at /home/bmerry/src/llvm/tools/clang/lib/Serialization/ASTReaderDecl.cpp:524
#27 0x00007fffca68adcf in clang::ASTDeclReader::VisitDeclaratorDecl (
    this=0x7fffc68e8f90, DD=0x7fffba76c290)
    at /home/bmerry/src/llvm/tools/clang/lib/Serialization/ASTReaderDecl.cpp:536
#28 0x00007fffca68af46 in clang::ASTDeclReader::VisitFunctionDecl (
    this=0x7fffc68e8f90, FD=0x7fffba76c290)
    at /home/bmerry/src/llvm/tools/clang/lib/Serialization/ASTReaderDecl.cpp:548
#29 0x00007fffca690e0f in clang::ASTDeclReader::VisitCXXMethodDecl (
    this=0x7fffc68e8f90, D=0x7fffba76c290)
    at /home/bmerry/src/llvm/tools/clang/lib/Serialization/ASTReaderDecl.cpp:1336
#30 0x00007fffca697edd in clang::declvisitor::Base<clang::declvisitor::make_ptr, clang::ASTDeclReader, void>::Visit (this=0x7fffc68e8f90, D=0x7fffba76c290)
    at /home/bmerry/src/llvm/build/tools/clang/lib/Serialization/../../include/clang/AST/DeclNodes.inc:349

<snip a lot more backtrace>

#150 0x00007fffca4c2aef in clang::FrontendAction::Execute (
    this=0x7fffb8001150)
    at /home/bmerry/src/llvm/tools/clang/lib/Frontend/FrontendAction.cpp:378
#151 0x00007fffca45ad74 in clang::ASTUnit::Parse (this=0x7fffb8006150, 
    OverrideMainBuffer=0x7fffade92880)
    at /home/bmerry/src/llvm/tools/clang/lib/Frontend/ASTUnit.cpp:1227
#152 0x00007fffca4601d5 in clang::ASTUnit::Reparse (this=0x7fffb8006150, 
    RemappedFiles=0x7fffb80010d0, NumRemappedFiles=1)
    at /home/bmerry/src/llvm/tools/clang/lib/Frontend/ASTUnit.cpp:2125
#153 0x00007fffca34fb3c in clang_reparseTranslationUnit_Impl (
    UserData=0x7fffc70faad0)
    at /home/bmerry/src/llvm/tools/clang/tools/libclang/CIndex.cpp:2963
#154 0x00007fffc8e91ad6 in llvm::CrashRecoveryContext::RunSafely (
    this=0x7fffc70faac0, 
    Fn=0x7fffca34f860 <clang_reparseTranslationUnit_Impl(void*)>, 
    UserData=0x7fffc70faad0)
    at /home/bmerry/src/llvm/lib/Support/CrashRecoveryContext.cpp:316
#155 0x00007fffc8e91d50 in RunSafelyOnThread_Dispatch (
    UserData=0x7fffc70faa00)
    at /home/bmerry/src/llvm/lib/Support/CrashRecoveryContext.cpp:347
#156 0x00007fffc8ed447e in ExecuteOnThread_Dispatch (Arg=0x7fffc70fa9b8)
    at /home/bmerry/src/llvm/lib/Support/Threading.cpp:75
#157 0x00007ffff4c50f6e in start_thread (arg=0x7fffc68fb700)
    at pthread_create.c:311
#158 0x00007ffff3ce79cd in clone ()
    at ../sysdeps/unix/sysv/linux/x86_64/clone.S:113