Bug 360707 - KDevelop crashes during parsing a project when it is compiled with GCC 6.0 (due to "remove null pointer checks for 'this' optimization") [KDevelop::AbstractType::indexed]
Summary: KDevelop crashes during parsing a project when it is compiled with GCC 6.0 (d...
Status: RESOLVED FIXED
Alias: None
Product: kdevelop
Classification: Applications
Component: general (show other bugs)
Version: 4.90.91
Platform: Compiled Sources Linux
: HI crash
Target Milestone: 5.0.0
Assignee: kdevelop-bugs-null
URL:
Keywords: junior-jobs, release_blocker
: 364028 364672 364697 364750 364819 365752 366433 (view as bug list)
Depends on:
Blocks:
 
Reported: 2016-03-18 15:28 UTC by Jan Grulich
Modified: 2016-10-10 09:29 UTC (History)
12 users (show)

See Also:
Latest Commit:
Version Fixed In: 4.7.4


Attachments
backtrace (35.44 KB, text/plain)
2016-03-18 16:11 UTC, Jan Grulich
Details
KDevelop build log (1.20 MB, text/plain)
2016-03-18 16:28 UTC, Jan Grulich
Details
KDevelop 5 crash backtrace (63.11 KB, text/plain)
2016-03-21 10:22 UTC, Jan Grulich
Details
KDevelop 5 crash backtrace (#2) (21.47 KB, text/plain)
2016-03-21 12:57 UTC, Jan Grulich
Details
New crash information added by DrKonqi (14.59 KB, text/plain)
2016-06-28 01:12 UTC, robert.berec
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jan Grulich 2016-03-18 15:28:12 UTC
Reproducible with KDevelop 4.7.3 or KDevelop 5.0 beta. We now have GCC 6.0 in Fedora 24 and this makes KDevelop unusable.

Relevant information from GCC release notes:
Value range propagation now assumes that the this pointer of C++ member functions is non-null. This eliminates common null pointer checks but also breaks some non-conforming code-bases (such as Qt-5, Chromium, KDevelop). As a temporary work-around -fno-delete-null-pointer-checks can be used. Wrong code can be identified by using -fsanitize=undefined.

I tried to use "-fno-delete-null-pointer-checks" and that solution worked for me. I can workaround this temporarily for our Fedora packages, but this should be rather fixed in KDevelop itself.



Reproducible: Always
Comment 1 Kevin Funk 2016-03-18 15:32:46 UTC
Where are the problems? Do you get compile errors with GCC6 without additional compiler flags? If yes, please post them.
Comment 2 Jan Grulich 2016-03-18 16:11:18 UTC
Created attachment 97959 [details]
backtrace

I didn't see any compilation error, it compiles just fine, it crashes later once I try to open any project. 

Attaching backtrace of the crash with KDevelop 4.7.3.
Comment 3 Jan Grulich 2016-03-18 16:28:51 UTC
Created attachment 97960 [details]
KDevelop build log

Also attaching build log in hope that may help.
Comment 4 Kevin Funk 2016-03-18 16:43:17 UTC
Git commit 513519edb3fa25d39370cee71b4813741994dd20 by Kevin Funk.
Committed on 18/03/2016 at 16:41.
Pushed by kfunk into branch '1.7'.

Fix -fdelete-null-pointer-checks issues

Prepare for upcoming GCC6, which sets this by default

M  +2    -3    language/duchain/topducontext.cpp

http://commits.kde.org/kdevplatform/513519edb3fa25d39370cee71b4813741994dd20
Comment 5 Kevin Funk 2016-03-18 16:45:45 UTC
Sorry, I don't have GCC6 around + I am reluctant to install it (breaks my Clang setup here, don't ask).

Please check if this solves the crash for you. I'm not sure the compiler warnings in KTextEditor (-Waddress) are problematic. Didn't check.
Comment 6 Jan Grulich 2016-03-21 10:22:17 UTC
Created attachment 98003 [details]
KDevelop 5 crash backtrace

The fix above helped to KDevelop 4.7 (at least I managed to open a project successfully) , but KDevelop 5.0 still crashes. See the attached backtrace.
Comment 7 Kevin Funk 2016-03-21 11:05:56 UTC
Git commit 935756dbab00479954d905d8ea4b29e3bd2e5647 by Kevin Funk.
Committed on 21/03/2016 at 10:36.
Pushed by kfunk into branch '1.7'.

Fix -fdelete-null-pointer-checks issues

Backtrace (reduced):
10 0x00007fc2221b9e9c in KDevelop::AbstractType::indexed() const
(this=0x0) at
/home/jgrulich/development/projects/kdevplatform/language/duchain/types/abstracttype.cpp:99
11 0x00007fc22212f4a6 in
KDevelop::Declaration::setAbstractType(KDevelop::TypePtr<KDevelop::AbstractType>)
(this=0x7fc1b40a42a0, type=...) at
/home/jgrulich/development/projects/kdevplatform/language/duchain/declaration.cpp:269
12 0x00007fc1f1eb988e in (anonymous
namespace)::Visitor::setDeclType<(CXCursorKind)10>(KDevelop::Declaration*,
KDevelop::AbstractType*) (decl=<optimized out>, type=<optimized out>,
this=<optimized out>) at
/home/jgrulich/development/projects/kdevelop/languages/clang/duchain/builder.cpp:786

M  +1    -1    language/duchain/declaration.cpp

http://commits.kde.org/kdevplatform/935756dbab00479954d905d8ea4b29e3bd2e5647
Comment 8 Jan Grulich 2016-03-21 12:57:43 UTC
Created attachment 98004 [details]
KDevelop 5 crash backtrace (#2)

Now I can open a project, but once I move the mouse cursor to some text to visualize the help, it crashes again. Backtrace attached.
Comment 9 Kevin Funk 2016-03-21 14:18:14 UTC
Alright. I need to test this properly. Uses of AbstractType::indexed seem like a can of worms, most of the callers don't check AbstractType*.

Thanks for testing Jan, so far, unfortunately the true fix might need to wait until I have GCC6 infrastructure ready.
Comment 10 Jonathan Wakely 2016-03-21 15:05:24 UTC
You don't need GCC 6, you should be able to find the null dereferences using ubsan in GCC 5, and maybe 4.9 too.

But building GCC 6 isn't a big deal. https://gcc.gnu.org/wiki/InstallingGCC
Comment 11 Jonathan Wakely 2016-03-21 15:12:11 UTC
(In reply to Kevin Funk from comment #9)
> Alright. I need to test this properly. Uses of AbstractType::indexed seem
> like a can of worms, most of the callers don't check AbstractType*.

Could it be solved with the NullObject pattern? i.e. make abstractType() always return a valid non-null pointer, returning a pointer to some global, empty/default/dumb object instead of null. That would mean that m_baseType->abstractType()->indexed() never dereferences null, and you don't need to fix every caller.
Comment 12 Kevin Funk 2016-03-21 23:38:13 UTC
Git commit 5ea89d672f288fc1233af86548f11388e6076e3d by Kevin Funk.
Committed on 21/03/2016 at 23:37.
Pushed by kfunk into branch '1.7'.

Fix places with undefined behavior

New API: IndexedType::IndexedType(const AbstractType::Ptr& type)

Places where we may call AbstractPtr::indexed with this being a nullptr.

M  +1    -1    language/duchain/instantiationinformation.cpp
M  +1    -1    language/duchain/repositories/typerepository.cpp
M  +1    -1    language/duchain/repositories/typerepository.h
M  +1    -1    language/duchain/types/abstracttype.cpp
M  +2    -2    language/duchain/types/arraytype.cpp
M  +2    -2    language/duchain/types/containertypes.cpp
M  +2    -2    language/duchain/types/containertypes.h
M  +5    -5    language/duchain/types/functiontype.cpp
M  +7    -0    language/duchain/types/indexedtype.cpp
M  +1    -3    language/duchain/types/indexedtype.h
M  +2    -2    language/duchain/types/pointertype.cpp
M  +2    -2    language/duchain/types/referencetype.cpp
M  +2    -2    language/duchain/types/typealiastype.cpp

http://commits.kde.org/kdevplatform/5ea89d672f288fc1233af86548f11388e6076e3d
Comment 13 Kevin Funk 2016-03-21 23:40:12 UTC
Git commit ca8d751a20b5d1e7b028af39e78547fc0e9d696b by Kevin Funk.
Committed on 21/03/2016 at 23:39.
Pushed by kfunk into branch '4.7'.

Fix places with undefined behavior

New API: IndexedType::IndexedType(const AbstractType::Ptr& type)

Places where we may call AbstractPtr::indexed with this being a nullptr.

Similar patches probably need to be applied to other language plugins

CCMAIL: kdevelop-devel@kde.org

M  +3    -1    languages/cpp/cppduchain/cppducontext.h
M  +3    -3    languages/cpp/cppduchain/declarationbuilder.cpp
M  +1    -1    languages/cpp/cppduchain/expressionparser.cpp
M  +2    -2    languages/cpp/cppduchain/name_visitor.cpp
M  +2    -2    languages/cpp/cppduchain/templatedeclaration.cpp
M  +3    -3    languages/cpp/cppduchain/typeconversion.cpp
M  +2    -2    languages/cpp/cppduchain/typeutils.cpp

http://commits.kde.org/kdevelop/ca8d751a20b5d1e7b028af39e78547fc0e9d696b
Comment 14 Kevin Funk 2016-03-22 12:29:02 UTC
Git commit 0101b7da8d88e01692ca2615d4b1704edac656a1 by Kevin Funk.
Committed on 22/03/2016 at 12:06.
Pushed by kfunk into branch '1.7'.

Fix null-pointer dereference

M  +2    -2    language/codecompletion/codecompletionitem.cpp

http://commits.kde.org/kdevplatform/0101b7da8d88e01692ca2615d4b1704edac656a1
Comment 15 Kevin Funk 2016-03-22 13:55:42 UTC
Git commit 315957c92f52c3bf89c85b9aa4fc13fec7a67e03 by Kevin Funk.
Committed on 22/03/2016 at 13:54.
Pushed by kfunk into branch '5.0'.

QmlJS: Protect against null-pointer derefs

M  +1    -1    languages/qmljs/duchain/declarationbuilder.cpp

http://commits.kde.org/kdevelop/315957c92f52c3bf89c85b9aa4fc13fec7a67e03
Comment 16 Kevin Funk 2016-03-22 13:55:42 UTC
Git commit 4510bbd27031498be2bd4bf8450af1be735e34dd by Kevin Funk.
Committed on 22/03/2016 at 13:54.
Pushed by kfunk into branch '5.0'.

Clang: Protect against null-pointer derefs

M  +1    -1    languages/clang/codegen/adaptsignatureassistant.cpp
M  +2    -2    languages/clang/codegen/codegenhelper.cpp
M  +1    -1    languages/clang/codegen/sourcemanipulation.cpp

http://commits.kde.org/kdevelop/4510bbd27031498be2bd4bf8450af1be735e34dd
Comment 17 Kevin Funk 2016-04-01 09:00:26 UTC
All issues in kdevplatform/kdevelop resolved.
Comment 18 Kevin Funk 2016-06-10 11:54:25 UTC
*** Bug 364028 has been marked as a duplicate of this bug. ***
Comment 19 fantaz 2016-06-23 13:19:47 UTC
Please, 
Where on earth can one install/download version 4.7.4? Don't see it on http://download.kde.org/stable/kdevelop/, nor it is in opensuse's tumbleweed repo...
Comment 20 Kevin Funk 2016-06-25 07:23:34 UTC
Nowhere, because it isn't released (yet?).
Comment 21 dontarius 2016-06-25 15:27:26 UTC
*** Bug 364750 has been marked as a duplicate of this bug. ***
Comment 22 robert.berec 2016-06-28 01:12:07 UTC
Created attachment 99737 [details]
New crash information added by DrKonqi

kdevelop (4.7.3) on KDE Platform 4.14.21 using Qt 4.8.7

KDevelop crashes every time I open it.

-- Backtrace (Reduced):
#6  0x00007fae0bd5246c in KDevelop::AbstractType::indexed() const () at /usr/lib64/libkdevplatformlanguage.so.8
#7  0x00007fad52ff0dec in Cpp::ExpressionParser::evaluateType(AST*, ParseSession*, KDevelop::TopDUContext const*) () at /usr/lib64/libkdev4cppduchain.so
#8  0x00007fad52fb4531 in TypeBuilder::visitSimpleTypeSpecifier(SimpleTypeSpecifierAST*) () at /usr/lib64/libkdev4cppduchain.so
#9  0x00007fad52cbf236 in DefaultVisitor::visitTypedef(TypedefAST*) () at /usr/lib64/libkdev4cppparser.so
#10 0x00007fad52f80c42 in ContextBuilder::visitTypedef(TypedefAST*) () at /usr/lib64/libkdev4cppduchain.so
Comment 23 Kevin Funk 2016-08-05 06:35:53 UTC
*** Bug 366433 has been marked as a duplicate of this bug. ***
Comment 24 Kevin Funk 2016-08-25 21:58:21 UTC
@Jan: Can you confirm all issues have been resolved? Does KDevelop work for you?
Comment 25 Kevin Funk 2016-08-25 21:58:44 UTC
Did you also try kdev-php & kdev-python?
Comment 26 Kevin Funk 2016-09-07 07:34:09 UTC
*** Bug 364672 has been marked as a duplicate of this bug. ***
Comment 27 Kevin Funk 2016-09-08 10:31:33 UTC
*** Bug 364697 has been marked as a duplicate of this bug. ***
Comment 28 Kevin Funk 2016-09-08 10:32:12 UTC
*** Bug 364819 has been marked as a duplicate of this bug. ***
Comment 29 Kevin Funk 2016-10-10 09:29:41 UTC
*** Bug 365752 has been marked as a duplicate of this bug. ***