Bug 374234 - KDevelop frozen when parsing llvm+clang source code
Summary: KDevelop frozen when parsing llvm+clang source code
Status: RESOLVED INTENTIONAL
Alias: None
Product: kdevelop
Classification: Applications
Component: Language Support: CPP (Clang-based) (other bugs)
Version First Reported In: git master
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: kdevelop-bugs-null
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-12-28 05:06 UTC by Leslie Zhai
Modified: 2016-12-29 08:24 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Leslie Zhai 2016-12-28 05:06:08 UTC
Hi KDevelop developers,

When I Open/Import LLVM projects and clicked the QTreeView llvm/tools/clang/lib/StaticAnalyzer/Checkers, KDevelop freezed!

There are 4 threads involved in parsing the huge LLVM projects, and htop to see CPU is 100, and command line show libclang error such as:

libclang: crash detected during parsing: {
  'source_filename' : '/data/project/LLVM/llvm/tools/clang/test/Driver/rewrite-map-in-diagnostics.c'
  'command_line_args' : ['clang', '-ferror-limit=100', '-fspell-checking', '-Wdocumentation', '-Wunused-parameter', '-Wunreachable-code', '-Wall', '-std=c99', '-nostdinc', '-xc', '-isystem/usr/local/include', '-isystem/usr/lib/clang/3.9.1/include', '-isystem/usr/include', '-imacros', '/tmp/kdevelop.JZ7809'],
  'unsaved_files' : [('/data/project/LLVM-China/tartan/clang-plugin/plugin.cpp', '...', 12414), ('/data/project/LLVM/llvm/tools/clang/lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp', '...', 9378), ('/data/project/LLVM/llvm/tools/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp', '...', 102293), ('/data/project/LLVM-China/tartan/clang-plugin/gerror-checker.h', '...', 7494), ('/data/project/LLVM-China/tartan/clang-plugin/gerror-checker.cpp', '...', 40442)],
  'options' : 557,
}
clang_parseTranslationUnit2 return with error code 2
  (start KDevelop with `KDEV_CLANG_DISPLAY_DIAGS=1 kdevelop` to see more diagnostics)
Failed to parse translation unit: "/data/project/LLVM/llvm/tools/clang/test/Driver/rewrite-map-in-diagnostics.c"

Regards,
Leslie Zhai
Comment 1 Leslie Zhai 2016-12-28 08:37:34 UTC
Then segfault:

* thread #39: tid = 26493, 0x00007fff3a256ea3 libclang.so.3.9`___lldb_unnamed_symbol20982$$libclang.so.3.9 + 3971, name = 'Queue(0xaf1430)', stop reason = signal SIGILL: illegal instruction operand
    frame #0: 0x00007fff3a256ea3 libclang.so.3.9`___lldb_unnamed_symbol20982$$libclang.so.3.9 + 3971
libclang.so.3.9`___lldb_unnamed_symbol20982$$libclang.so.3.9:
->  0x7fff3a256ea3 <+3971>: ud2    
    0x7fff3a256ea5 <+3973>: callq  0x7fff3968e7e0            ; symbol stub for: __stack_chk_fail
    0x7fff3a256eaa <+3978>: nopw   (%rax,%rax)

libclang.so.3.9`___lldb_unnamed_symbol20983$$libclang.so.3.9:
    0x7fff3a256eb0 <+0>:    movq   0x8(%rsi), %rax
(lldb) bt
* thread #39: tid = 26493, 0x00007fff3a256ea3 libclang.so.3.9`___lldb_unnamed_symbol20982$$libclang.so.3.9 + 3971, name = 'Queue(0xaf1430)', stop reason = signal SIGILL: illegal instruction operand
  * frame #0: 0x00007fff3a256ea3 libclang.so.3.9`___lldb_unnamed_symbol20982$$libclang.so.3.9 + 3971
    frame #1: 0x00007fff3a24d41a libclang.so.3.9`___lldb_unnamed_symbol20961$$libclang.so.3.9 + 2090
    frame #2: 0x00007fff3a24da22 libclang.so.3.9`___lldb_unnamed_symbol20962$$libclang.so.3.9 + 18
    frame #3: 0x00007fff3a250293 libclang.so.3.9`___lldb_unnamed_symbol20970$$libclang.so.3.9 + 643
    frame #4: 0x00007fff3a22c822 libclang.so.3.9`___lldb_unnamed_symbol20840$$libclang.so.3.9 + 290
    frame #5: 0x00007fff3a22cf01 libclang.so.3.9`___lldb_unnamed_symbol20841$$libclang.so.3.9 + 913
    frame #6: 0x00007fff3a22cf3f libclang.so.3.9`___lldb_unnamed_symbol20842$$libclang.so.3.9 + 31
    frame #7: 0x00007fff3a23431f libclang.so.3.9`___lldb_unnamed_symbol20861$$libclang.so.3.9 + 287
    frame #8: 0x00007fff3a234cfc libclang.so.3.9`___lldb_unnamed_symbol20862$$libclang.so.3.9 + 460
    frame #9: 0x00007fff3a2281f0 libclang.so.3.9`___lldb_unnamed_symbol20802$$libclang.so.3.9 + 672
    frame #10: 0x00007fff399c3ace libclang.so.3.9`___lldb_unnamed_symbol8518$$libclang.so.3.9 + 286
    frame #11: 0x00007fff3997f497 libclang.so.3.9`___lldb_unnamed_symbol8198$$libclang.so.3.9 + 1655
    frame #12: 0x00007fff3998289b libclang.so.3.9`___lldb_unnamed_symbol8203$$libclang.so.3.9 + 443
    frame #13: 0x00007fff39986497 libclang.so.3.9`___lldb_unnamed_symbol8217$$libclang.so.3.9 + 1623
    frame #14: 0x00007fff397600f0 libclang.so.3.9`___lldb_unnamed_symbol3306$$libclang.so.3.9 + 2144
    frame #15: 0x00007fff36c32539 libLLVM-3.9.so`llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) + 153
    frame #16: 0x00007fff36c325a4 libLLVM-3.9.so`___lldb_unnamed_symbol811$$libLLVM-3.9.so + 20
    frame #17: 0x00007fff36cacbdd libLLVM-3.9.so`___lldb_unnamed_symbol1027$$libLLVM-3.9.so + 13
    frame #18: 0x00007fffe6ba4454 libpthread.so.0`start_thread + 196
    frame #19: 0x00007ffff03c87df libc.so.6`__GI___clone + 95
(lldb)
Comment 2 Sven Brauch 2016-12-28 17:03:04 UTC
Looks like a bug in libclang and should probably be reported / tracked there.
Comment 3 Leslie Zhai 2016-12-29 05:12:52 UTC
Hi Sven,

Thanks for your reply!

I will report libclang bug to LLVM UPSTREAM, but how to workaround the freeze issue?

Regards,
Leslie Zhai
Comment 4 Leslie Zhai 2016-12-29 06:16:55 UTC
PS: libclang crashes when parsing https://llvm.org/bugs/show_bug.cgi?id=13619
Comment 5 Kevin Funk 2016-12-29 08:24:48 UTC
Hmmm, I actually replied to this one, but maybe forgot to send it.

The problem here: Every now and then bugs which crash Clang/LLVM are detected, caused by non-common source files. Developers will add these source files as regression tests into Clang/LLVM trunk which they commit along-side with the crash-fix.

Now if you work with KDevelop on the Clang/LLVM trunk, KDevelop using the *older* Clang/LLVM version will try to parse those regression tests and run into the crash which was fixed in Clang/LLVM trunk already.

There's no easy solution to it, the only thing you can do is to make sure KDevelop (rather: libclang) never gets to see those source files to begin with:

Try to make the background parser ignore those files: See http://comments.gmane.org/gmane.comp.kde.users.kdevelop/7102 for information how to do that.