[llvm-bugs] [Bug 25536] New: libclang crashes on code completion at macro expansion

via llvm-bugs llvm-bugs at lists.llvm.org
Sun Nov 15 10:50:37 PST 2015


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

            Bug ID: 25536
           Summary: libclang crashes on code completion at macro expansion
           Product: clang
           Version: 3.7
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: libclang
          Assignee: unassignedclangbugs at nondot.org
          Reporter: rwindz0 at gmail.com
                CC: klimek at google.com, llvm-bugs at lists.llvm.org
    Classification: Unclassified

I faced this bug since clang 3.7 (it seems clang 3.6 never crashes on the same
code)

You can repeat this issue if you are using YouCompleteMe or similar
libclang-based completer on this code (assuming we have include googletest
headers):

  ASSERT_EQ(CXError_Success,
            Instance->
                     ^

> ASSERT_EQ is macro here, CXError_Success is enum, and Instance is a pointer to some class.

Try to trigger the completer, then delete the right-arrow and trigger it again.
You should get a crash.

However if you use c-index-test to get the completions, you won't get crashed.
As the backtrace showing below, it seems to be a bug with unsaved files and
code completion internal cache.

Here is a backtrace from one of my crashes (with export LIBCLANG_NOTHREADS=1):

(lldb) bt
* thread #1: tid = 0x3fc88, 0x00007fff8f1930ae
libsystem_kernel.dylib`__pthread_kill + 10, queue = 'com.apple.main-thread',
stop reason = signal SIGABRT
  * frame #0: 0x00007fff8f1930ae libsystem_kernel.dylib`__pthread_kill + 10
    frame #1: 0x00007fff965f2500 libsystem_pthread.dylib`pthread_kill + 90
    frame #2: 0x0000000102de56eb libclang.3.7.dylib`::raise(sig=6) + 27 at
Signals.inc:536
    frame #3: 0x0000000102de5792 libclang.3.7.dylib`::abort() + 18 at
Signals.inc:553
    frame #4: 0x0000000102de577e
libclang.3.7.dylib`::__assert_rtn(func="getRawTextSlow",
file="/Users/ch/sources-llvm/llvm_37/tools/clang/lib/AST/RawCommentList.cpp",
line=107, expr="BeginFileID == EndFileID") + 126 at Signals.inc:549
    frame #5: 0x000000010061ebaa
libclang.3.7.dylib`clang::RawComment::getRawTextSlow(this=0x00007fff5fbf56e0,
SourceMgr=0x0000000112139c40) const + 1322 at RawCommentList.cpp:107
    frame #6: 0x00000001001eda30
libclang.3.7.dylib`clang::RawComment::getRawText(this=0x00007fff5fbf56e0,
SourceMgr=0x0000000112139c40) const + 80 at RawCommentList.h:105
    frame #7: 0x000000010061dbe5
libclang.3.7.dylib`clang::RawComment::RawComment(this=0x00007fff5fbf56e0,
SourceMgr=0x0000000112139c40, SR=SourceRange @ 0x00007fff5fbf5590,
Merged=false, ParseAllComments=false) + 245 at RawCommentList.cpp:73
    frame #8: 0x000000010061e66c
libclang.3.7.dylib`clang::RawComment::RawComment(this=0x00007fff5fbf56e0,
SourceMgr=0x0000000112139c40, SR=SourceRange @ 0x00007fff5fbf55c8,
Merged=false, ParseAllComments=false) + 76 at RawCommentList.cpp:71
    frame #9: 0x0000000100b3cb98
libclang.3.7.dylib`clang::Sema::ActOnComment(this=0x0000000110af2200,
Comment=SourceRange @ 0x00007fff5fbf5718) + 168 at Sema.cpp:1208
    frame #10: 0x000000010300607d libclang.3.7.dylib`(anonymous
namespace)::ActionCommentHandler::HandleComment(this=0x0000000112146ad0,
PP=0x0000000110804e00, Comment=SourceRange @ 0x00007fff5fbf5748) + 45 at
Parser.cpp:37
    frame #11: 0x0000000100a8f91a
libclang.3.7.dylib`clang::Preprocessor::HandleComment(this=0x0000000110804e00,
result=0x00007fff5fbf5f70, Comment=SourceRange @ 0x00007fff5fbf57a0) + 442 at
Preprocessor.cpp:887
    frame #12: 0x00000001009f4d4c
libclang.3.7.dylib`clang::Lexer::SkipLineComment(this=0x00000001121487d0,
Result=0x00007fff5fbf5f70, CurPtr="",
TokAtPhysicalStartOfLine=0x00007fff5fbf5af7) + 1356 at Lexer.cpp:2115
    frame #13: 0x00000001009f8734
libclang.3.7.dylib`clang::Lexer::LexTokenInternal(this=0x00000001121487d0,
Result=0x00007fff5fbf5f70, TokAtPhysicalStartOfLine=false) + 5316 at
Lexer.cpp:3322
    frame #14: 0x00000001009f60b8
libclang.3.7.dylib`clang::Lexer::Lex(this=0x00000001121487d0,
Result=0x00007fff5fbf5f70) + 216 at Lexer.cpp:2888
    frame #15: 0x0000000100a8dafe
libclang.3.7.dylib`clang::Preprocessor::Lex(this=0x0000000110804e00,
Result=0x00007fff5fbf5f70) + 126 at Preprocessor.cpp:720
    frame #16: 0x0000000100a90e30
libclang.3.7.dylib`clang::Preprocessor::LexUnexpandedToken(this=0x0000000110804e00,
Result=0x00007fff5fbf5f70) + 80 at Preprocessor.h:1099
    frame #17: 0x0000000100a59c46
libclang.3.7.dylib`clang::Preprocessor::ReadFunctionLikeMacroArgs(this=0x0000000110804e00,
MacroName=0x0000000110af4810, MI=0x0000000110b3f718,
MacroEnd=0x00007fff5fbf68c0) + 550 at PPMacroExpansion.cpp:745
    frame #18: 0x0000000100a571b2
libclang.3.7.dylib`clang::Preprocessor::HandleMacroExpandedIdentifier(this=0x0000000110804e00,
Identifier=0x0000000110af4810, M=0x00007fff5fbf6a20) + 498 at
PPMacroExpansion.cpp:448
    frame #19: 0x0000000100a8d5cf
libclang.3.7.dylib`clang::Preprocessor::HandleIdentifier(this=0x0000000110804e00,
Identifier=0x0000000110af4810) + 671 at Preprocessor.cpp:659
    frame #20: 0x00000001009f2a6c
libclang.3.7.dylib`clang::Lexer::LexIdentifier(this=0x00000001121487d0,
Result=0x0000000110af4810, CurPtr="(CXError_Success,\n            Instance-") +
332 at Lexer.cpp:1504
    frame #21: 0x00000001009f8003
libclang.3.7.dylib`clang::Lexer::LexTokenInternal(this=0x00000001121487d0,
Result=0x0000000110af4810, TokAtPhysicalStartOfLine=true) + 3475 at
Lexer.cpp:3173
    frame #22: 0x00000001009f60b8
libclang.3.7.dylib`clang::Lexer::Lex(this=0x00000001121487d0,
Result=0x0000000110af4810) + 216 at Lexer.cpp:2888
    frame #23: 0x0000000100a8dafe
libclang.3.7.dylib`clang::Preprocessor::Lex(this=0x0000000110804e00,
Result=0x0000000110af4810) + 126 at Preprocessor.cpp:720
    frame #24: 0x0000000100a285e0
libclang.3.7.dylib`clang::Preprocessor::CachingLex(this=0x0000000110804e00,
Result=0x0000000110af4810) + 192 at PPCaching.cpp:58
    frame #25: 0x0000000100a8db85
libclang.3.7.dylib`clang::Preprocessor::Lex(this=0x0000000110804e00,
Result=0x0000000110af4810) + 261 at Preprocessor.cpp:729
    frame #26: 0x00000001030064b9
libclang.3.7.dylib`clang::Parser::ConsumeToken(this=0x0000000110af4800) + 153
at Parser.h:288
    frame #27: 0x0000000102ffc602
libclang.3.7.dylib`clang::Parser::SkipUntil(this=0x0000000110af4800,
Toks=ArrayRef<clang::tok::TokenKind> @ 0x00007fff5fbf6f18,
Flags=StopAtCodeCompletion) + 1362 at Parser.cpp:360
    frame #28: 0x0000000103006626
libclang.3.7.dylib`clang::Parser::SkipUntil(this=0x0000000110af4800, T=r_brace,
Flags=StopAtCodeCompletion) + 70 at Parser.h:863
    frame #29: 0x0000000102fe64cc
libclang.3.7.dylib`clang::Parser::trySkippingFunctionBody(this=0x0000000110af4800)
+ 284 at ParseStmt.cpp:1940
    frame #30: 0x0000000102fe624d
libclang.3.7.dylib`clang::Parser::ParseFunctionStatementBody(this=0x0000000110af4800,
Decl=0x00000001119cdf78, BodyScope=0x00007fff5fbf7230) + 205 at
ParseStmt.cpp:1865
    frame #31: 0x00000001030021fa
libclang.3.7.dylib`clang::Parser::ParseFunctionDefinition(this=0x0000000110af4800,
D=0x00007fff5fbf77f8, TemplateInfo=0x00007fff5fbf7638,
LateParsedAttrs=0x00007fff5fbf77c8) + 3690 at Parser.cpp:1137
    frame #32: 0x0000000102f54e59
libclang.3.7.dylib`clang::Parser::ParseDeclGroup(this=0x0000000110af4800,
DS=0x00007fff5fbf8058, Context=0, DeclEnd=0x0000000000000000,
FRI=0x0000000000000000) + 1033 at ParseDecl.cpp:1760
    frame #33: 0x0000000103001374
libclang.3.7.dylib`clang::Parser::ParseDeclOrFunctionDefInternal(this=0x0000000110af4800,
attrs=0x00007fff5fbf85d8, DS=0x00007fff5fbf8058, AS=AS_none) + 1140 at
Parser.cpp:926
    frame #34: 0x0000000103000b32
libclang.3.7.dylib`clang::Parser::ParseDeclarationOrFunctionDefinition(this=0x0000000110af4800,
attrs=0x00007fff5fbf85d8, DS=0x0000000000000000, AS=AS_none) + 194 at
Parser.cpp:942
    frame #35: 0x0000000103000368
libclang.3.7.dylib`clang::Parser::ParseExternalDeclaration(this=0x0000000110af4800,
attrs=0x00007fff5fbf85d8, DS=0x0000000000000000) + 3688 at Parser.cpp:800
    frame #36: 0x0000000102f6c37a
libclang.3.7.dylib`clang::Parser::ParseInnerNamespace(this=0x0000000110af4800,
IdentLoc=size=0, Ident=size=0, NamespaceLoc=size=0, index=0,
InlineLoc=0x00007fff5fbf8bf0, attrs=0x00007fff5fbf8b38,
Tracker=0x00007fff5fbf8a00) + 298 at ParseDeclCXX.cpp:217
    frame #37: 0x0000000102f6bcf1
libclang.3.7.dylib`clang::Parser::ParseNamespace(this=0x0000000110af4800,
Context=0, DeclEnd=0x00007fff5fbf9470, InlineLoc=(ID = 0)) + 6625 at
ParseDeclCXX.cpp:193
    frame #38: 0x0000000102f50146
libclang.3.7.dylib`clang::Parser::ParseDeclaration(this=0x0000000110af4800,
Context=0, DeclEnd=0x00007fff5fbf9470, attrs=0x00007fff5fbf9648) + 614 at
ParseDecl.cpp:1478
    frame #39: 0x0000000102ffff76
libclang.3.7.dylib`clang::Parser::ParseExternalDeclaration(this=0x0000000110af4800,
attrs=0x00007fff5fbf9648, DS=0x0000000000000000) + 2678 at Parser.cpp:742
    frame #40: 0x0000000102f6c37a
libclang.3.7.dylib`clang::Parser::ParseInnerNamespace(this=0x0000000110af4800,
IdentLoc=size=0, Ident=size=0, NamespaceLoc=size=0, index=0,
InlineLoc=0x00007fff5fbf9c60, attrs=0x00007fff5fbf9ba8,
Tracker=0x00007fff5fbf9a70) + 298 at ParseDeclCXX.cpp:217
    frame #41: 0x0000000102f6bcf1
libclang.3.7.dylib`clang::Parser::ParseNamespace(this=0x0000000110af4800,
Context=0, DeclEnd=0x00007fff5fbfa4e0, InlineLoc=(ID = 0)) + 6625 at
ParseDeclCXX.cpp:193
    frame #42: 0x0000000102f50146
libclang.3.7.dylib`clang::Parser::ParseDeclaration(this=0x0000000110af4800,
Context=0, DeclEnd=0x00007fff5fbfa4e0, attrs=0x00007fff5fbfa6b8) + 614 at
ParseDecl.cpp:1478
    frame #43: 0x0000000102ffff76
libclang.3.7.dylib`clang::Parser::ParseExternalDeclaration(this=0x0000000110af4800,
attrs=0x00007fff5fbfa6b8, DS=0x0000000000000000) + 2678 at Parser.cpp:742
    frame #44: 0x0000000102f6c37a
libclang.3.7.dylib`clang::Parser::ParseInnerNamespace(this=0x0000000110af4800,
IdentLoc=size=0, Ident=size=0, NamespaceLoc=size=0, index=0,
InlineLoc=0x00007fff5fbfacd0, attrs=0x00007fff5fbfac18,
Tracker=0x00007fff5fbfaae0) + 298 at ParseDeclCXX.cpp:217
    frame #45: 0x0000000102f6bcf1
libclang.3.7.dylib`clang::Parser::ParseNamespace(this=0x0000000110af4800,
Context=0, DeclEnd=0x00007fff5fbfb550, InlineLoc=(ID = 0)) + 6625 at
ParseDeclCXX.cpp:193
    frame #46: 0x0000000102f50146
libclang.3.7.dylib`clang::Parser::ParseDeclaration(this=0x0000000110af4800,
Context=0, DeclEnd=0x00007fff5fbfb550, attrs=0x00007fff5fbfb700) + 614 at
ParseDecl.cpp:1478
    frame #47: 0x0000000102ffff76
libclang.3.7.dylib`clang::Parser::ParseExternalDeclaration(this=0x0000000110af4800,
attrs=0x00007fff5fbfb700, DS=0x0000000000000000) + 2678 at Parser.cpp:742
    frame #48: 0x0000000102fff4b7
libclang.3.7.dylib`clang::Parser::ParseTopLevelDecl(this=0x0000000110af4800,
Result=0x00007fff5fbfb840) + 951 at Parser.cpp:592
    frame #49: 0x0000000102f4211d
libclang.3.7.dylib`clang::ParseAST(S=0x0000000110af2200, PrintStats=false,
SkipFunctionBodies=false) + 733 at ParseAST.cpp:134
    frame #50: 0x0000000100950c9a
libclang.3.7.dylib`clang::ASTFrontendAction::ExecuteAction(this=0x000000011213afb0)
+ 506 at FrontendAction.cpp:536
    frame #51: 0x0000000100950230
libclang.3.7.dylib`clang::FrontendAction::Execute(this=0x000000011213afb0) +
112 at FrontendAction.cpp:439
    frame #52: 0x000000010089ce26
libclang.3.7.dylib`clang::ASTUnit::CodeComplete(this=0x000000010b800600,
File=(Data = "/Users/ch/windycode/src/ClangSupport/ClangInvoker_unittest.cc",
Length = 61), Line=88, Column=22,
RemappedFiles=ArrayRef<std::__1::pair<std::__1::basic_string<char>,
llvm::MemoryBuffer *> > @ 0x00007fff5fbfcaf0, IncludeMacros=true,
IncludeCodePatterns=false, IncludeBriefComments=false,
Consumer=0x00007fff5fbfcee8,
PCHContainerOps=std::__1::shared_ptr<clang::PCHContainerOperations>::element_type
@ 0x0000000109807768 strong=3 weak=1, Diag=0x0000000110a2c400,
LangOpts=0x0000000110a2a990, SourceMgr=0x0000000112139c40,
FileMgr=0x00000001099aaf10, StoredDiagnostics=0x0000000110a2a610,
OwnedBuffers=0x0000000110a2aad0) + 8358 at ASTUnit.cpp:2447
    frame #53: 0x000000010022c4d8
libclang.3.7.dylib`clang_codeCompleteAt_Impl(UserData=0x00007fff5fbfd160) +
2424 at CIndexCodeCompletion.cpp:717
    frame #54: 0x000000010022ba80
libclang.3.7.dylib`::clang_codeCompleteAt(TU=0x000000010995e8c0,
complete_filename="/Users/ch/windycode/src/ClangSupport/ClangInvoker_unittest.cc",
complete_line=88, complete_column=22, unsaved_files=0x0000000112646090,
num_unsaved_files=1, options=1) + 384 at CIndexCodeCompletion.cpp:829
    frame #55: 0x0000000100037803
wdcd`windycode::ClangSupport::ClangInvoker::codeCompleteAt(this=0x00000001000c8d38,
FileName=(Data =
"/Users/ch/windycode/src/ClangSupport/ClangInvoker_unittest.cc", Length = 61),
Line=88, Column=22, Results=0x00007fff5fbfe270) + 3267 at ClangInvoker.cc:179

BTW libclang on trunk crashes, but the one shipped with Xcode 7.1.1 doesn't at
all.

-- 
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/20151115/c4b91ca0/attachment.html>


More information about the llvm-bugs mailing list