Bug 358853 - include not found in a header causes random parsing/highlighting/code completion glitches
Summary: include not found in a header causes random parsing/highlighting/code complet...
Status: RESOLVED UPSTREAM
Alias: None
Product: kdevelop
Classification: Applications
Component: Language Support: CPP (Clang-based) (show other bugs)
Version: git master
Platform: unspecified Linux
: VHI major
Target Milestone: 5.0.0
Assignee: kdevelop-bugs-null
URL:
Keywords: release_blocker
Depends on:
Blocks:
 
Reported: 2016-02-01 01:33 UTC by David Nolden
Modified: 2016-03-02 21:25 UTC (History)
0 users

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 David Nolden 2016-02-01 01:33:06 UTC
When an include is not found (even if it's not needed at all), then the semantic analysis, highlighting, code completion, etc. becomes seriously broken. It seems that clang internally just stops processing the translation-unit at some point and leaves it half-processed.

Ideally this would be fixed in clang so that such situations are handled more gracefully. But before that, given how serious the implications are, KDevelop's problem reporter should at least show an error, pointing out the problem. Currently, when the #include was missing in a recursively included header, then the problem-reporter stays completely empty, leaving the user cluelessly with a half-processed document.

Reproducible: Always
Comment 1 Milian Wolff 2016-02-01 09:50:10 UTC
Agreed, on all parts. Esp. considering that we already offer a simple workaround for such problems (i.e. add manual include path), we should just show this to the user when we spot such an error anywhere in the include chain.
Comment 2 David Nolden 2016-02-01 15:53:51 UTC
Git commit 7bdc9e8d9539c6e904edbd021d0cc359cdc8e843 by David Nolden.
Committed on 01/02/2016 at 15:53.
Pushed by zwabel into branch 'master'.

Add a testcase for BUG: 358853

It seems to break as soon as the second missing
include is encountered.

M  +45   -0    languages/clang/tests/test_duchain.cpp
M  +1    -0    languages/clang/tests/test_duchain.h

http://commits.kde.org/kdevelop/7bdc9e8d9539c6e904edbd021d0cc359cdc8e843
Comment 3 Milian Wolff 2016-02-01 17:37:57 UTC
Maybe related upstream issue: https://llvm.org/bugs/show_bug.cgi?id=24268
Comment 4 David Nolden 2016-02-01 18:12:23 UTC
Git commit a1d6a13183c01b9ea2c45e470e81f9ec53df7ada by David Nolden.
Committed on 01/02/2016 at 18:11.
Pushed by zwabel into branch 'master'.

Always show recursive "missing include" errors in problem view

Extend the missing-include test so that it becomes a recursive
include and also tests this fix. The problem is only actually
visible together with my previous commit to kdevplatform.

M  +3    -1    languages/clang/duchain/parsesession.cpp
M  +12   -7    languages/clang/tests/test_duchain.cpp

http://commits.kde.org/kdevelop/a1d6a13183c01b9ea2c45e470e81f9ec53df7ada
Comment 5 David Nolden 2016-02-01 18:15:53 UTC
Git commit c9dcbaeedef2ec746214d1be91a09293492e4abb by David Nolden.
Committed on 01/02/2016 at 18:15.
Pushed by zwabel into branch '5.0'.

Add a testcase for BUG: 358853

It seems to break as soon as the second missing
include is encountered.

M  +45   -0    languages/clang/tests/test_duchain.cpp
M  +1    -0    languages/clang/tests/test_duchain.h

http://commits.kde.org/kdevelop/c9dcbaeedef2ec746214d1be91a09293492e4abb
Comment 6 David Nolden 2016-02-01 18:15:53 UTC
Git commit e90e1864039d8ea3c045d64dc35d117060c950b1 by David Nolden.
Committed on 01/02/2016 at 18:15.
Pushed by zwabel into branch '5.0'.

Always show recursive "missing include" errors in problem view

Extend the missing-include test so that it becomes a recursive
include and also tests this fix. The problem is only actually
visible together with my previous commit to kdevplatform.

M  +3    -1    languages/clang/duchain/parsesession.cpp
M  +12   -7    languages/clang/tests/test_duchain.cpp

http://commits.kde.org/kdevelop/e90e1864039d8ea3c045d64dc35d117060c950b1
Comment 7 David Nolden 2016-02-01 22:14:03 UTC
Git commit 0b506dcbee4c15d4e0f19308364f50cc19dcdbd2 by David Nolden.
Committed on 01/02/2016 at 22:13.
Pushed by zwabel into branch 'master'.

Workaround clang parsing problems when includes are missing

When an include was missing in a parse run, then the corresponding
include directive is removed from the parse using the unsaved-file
mechanism, and the document is re-parsed. This is repeated
until no more missing includes are found. The corresponding
missing-include problems are shown in the problem-reporter
anyway, so the user can fix it.

M  +2    -0    languages/clang/clangparsejob.cpp
M  +71   -4    languages/clang/duchain/parsesession.cpp
M  +9    -0    languages/clang/duchain/parsesession.h
M  +11   -0    languages/clang/duchain/unsavedfile.cpp
M  +4    -0    languages/clang/duchain/unsavedfile.h
M  +1    -5    languages/clang/tests/test_duchain.cpp

http://commits.kde.org/kdevelop/0b506dcbee4c15d4e0f19308364f50cc19dcdbd2
Comment 8 David Nolden 2016-02-03 22:19:23 UTC
Git commit 1dffa94f333098bca2830c9da96367156fc9b505 by David Nolden.
Committed on 03/02/2016 at 22:18.
Pushed by zwabel into branch '5.0'.

Workaround clang parsing problems when includes are missing

When an include was missing in a parse run, then the corresponding
include directive is removed from the parse using the unsaved-file
mechanism, and the document is re-parsed. This is repeated
until no more missing includes are found. The corresponding
missing-include problems are shown in the problem-reporter
anyway, so the user can fix it.

M  +2    -0    languages/clang/clangparsejob.cpp
M  +71   -4    languages/clang/duchain/parsesession.cpp
M  +9    -0    languages/clang/duchain/parsesession.h
M  +11   -0    languages/clang/duchain/unsavedfile.cpp
M  +4    -0    languages/clang/duchain/unsavedfile.h
M  +1    -5    languages/clang/tests/test_duchain.cpp

http://commits.kde.org/kdevelop/1dffa94f333098bca2830c9da96367156fc9b505
Comment 9 Milian Wolff 2016-02-14 14:33:32 UTC
The tentative was reverted as it introduced crashes such as the one shown in Bug 359031. We'll have to revise the patch and resubmit it.
Comment 10 Milian Wolff 2016-02-14 15:58:38 UTC
Git commit 140e6c8193711bfbc033cfde69144e0c60279528 by Milian Wolff.
Committed on 14/02/2016 at 15:17.
Pushed by mwolff into branch '5.0'.

Cleanup test case and broken comparison resulting in XPASS.

M  +18   -11   languages/clang/tests/test_duchain.cpp

http://commits.kde.org/kdevelop/140e6c8193711bfbc033cfde69144e0c60279528
Comment 11 Milian Wolff 2016-02-21 01:31:27 UTC
Proper fix proposed upstream: http://reviews.llvm.org/D17486, also note that this definitely corresponds to https://llvm.org/bugs/show_bug.cgi?id=24268
Comment 12 Milian Wolff 2016-03-02 10:39:04 UTC
Fixed upstream now, but we need to patch the code to pass CXTranslationUnit_KeepGoing when available.
Comment 13 Kevin Funk 2016-03-02 21:25:43 UTC
Git commit 8af21faaa88682dfb844cc2001a5b8c46eeff576 by Kevin Funk.
Committed on 02/03/2016 at 21:25.
Pushed by kfunk into branch '5.0'.

clang: Make use of CXTranslationUnit_KeepGoing

Differential Revision: https://phabricator.kde.org/D1051

M  +5    -1    languages/clang/duchain/parsesession.cpp
M  +11   -0    languages/clang/tests/test_duchain.cpp

http://commits.kde.org/kdevelop/8af21faaa88682dfb844cc2001a5b8c46eeff576