Bug 488069 - Reproducible crash in libclang after ::Visitor::setTypeSize
Summary: Reproducible crash in libclang after ::Visitor::setTypeSize
Status: REPORTED
Alias: None
Product: kdevelop
Classification: Applications
Component: Language Support: CPP (Clang-based) (other bugs)
Version First Reported In: git master
Platform: Compiled Sources Linux
: NOR crash
Target Milestone: ---
Assignee: kdevelop-bugs-null
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-06-05 12:53 UTC by Benjamin Huth
Modified: 2024-06-07 11:19 UTC (History)
1 user (show)

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


Attachments
source file to reproduce the crash (wrapped in archive because of file size) (715.73 KB, application/gzip)
2024-06-05 12:55 UTC, Benjamin Huth
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Benjamin Huth 2024-06-05 12:53:20 UTC
SUMMARY

Today I observed an crash in KDevelop, and I was able to extract a single source file that can reproduce the crash, see attached file (produced using g++ -E, so no includes required). 

The crash seems to happen in (anonymous namespace)::Visitor::setTypeSize in src/plugins/clang/duchain/builder.cpp:950

KDevelop is built from sources against clang version 18.1.1 (Fedora 18.1.1-1.fc40).

In principle I'm willing to look into this, but currently I do not have time, and maybe some experts already have an idea what this is.

Backtrace in gdb:

#0  0x00007fffa0ee4104 in clang::ASTContext::getTypeInfoImpl(clang::Type const*) const () at /lib64/libclang.so.18.1
#1  0x00007fffa0ee5d5a in clang::ASTContext::getTypeInfoInChars(clang::Type const*) const () at /lib64/libclang.so.18.1
#2  0x00007fffa0ee5c50 in clang::ASTContext::getTypeInfoInChars(clang::Type const*) const () at /lib64/libclang.so.18.1
#3  0x00007fffa0ec4efc in clang_Type_getSizeOf () at /lib64/libclang.so.18.1
#4  0x00007fffae29d9a6 in (anonymous namespace)::Visitor::setTypeSize (type=..., kdevType=kdevType@entry=0x7fff83b924b0, this=<optimized out>)
    at /home/benjamin/Developement/kdevelop/kdevelop/src/plugins/clang/duchain/builder.cpp:950
#5  0x00007fffae2a069d in (anonymous namespace)::Visitor::dispatchType<(CXTypeKind)177> (this=<optimized out>, type=..., cursor=...)
    at /home/benjamin/Developement/kdevelop/kdevelop/src/plugins/clang/duchain/builder.cpp:372
#6  (anonymous namespace)::Visitor::makeType (this=<optimized out>, type=..., parent=...) at /home/benjamin/Developement/kdevelop/kdevelop/src/plugins/clang/duchain/builder.cpp:1466
#7  0x00007fffae2aa455 in (anonymous namespace)::Visitor::createType<(CXCursorKind)10> (this=0x7fffa0bff6a0, cursor=...)
    at /home/benjamin/Developement/kdevelop/kdevelop/src/plugins/clang/duchain/builder.cpp:707
#8  (anonymous namespace)::Visitor::createDeclaration<(CXCursorKind)10, KDevelop::Declaration> (context=0x0, this=0x7fffa0bff6a0, cursor=..., id=...)
    at /home/benjamin/Developement/kdevelop/kdevelop/src/plugins/clang/duchain/builder.cpp:457
#9  (anonymous namespace)::Visitor::buildDeclaration<(CXCursorKind)10, KDevelop::Declaration, false> (this=this@entry=0x7fffa0bff6a0, cursor=...)
    at /home/benjamin/Developement/kdevelop/kdevelop/src/plugins/clang/duchain/builder.cpp:1296
#10 0x00007fffae2b2d6f in (anonymous namespace)::Visitor::dispatchCursor<(CXCursorKind)13, (Decision)1, (Decision)1> (this=0x7fffa0bff6a0, cursor=..., parent=...)
    at /home/benjamin/Developement/kdevelop/kdevelop/src/plugins/clang/duchain/builder.cpp:988


STEPS TO REPRODUCE
1. open empty session with empty project with attached file
2. wait a bit until background parser starts

OBSERVED RESULT
KDevelop crashes

EXPECTED RESULT
No crash

SOFTWARE/OS VERSIONS
Windows: 
macOS: 
Linux/KDE Plasma: 
(available in About System)
KDE Plasma Version: 
KDE Frameworks Version: 
Qt Version: 

ADDITIONAL INFORMATION
Comment 1 Benjamin Huth 2024-06-05 12:55:14 UTC
Created attachment 170166 [details]
source file to reproduce the crash (wrapped in archive because of file size)
Comment 2 Benjamin Huth 2024-06-05 12:57:21 UTC
In case its important, the system details:

Operating System: Fedora Linux 40
KDE Plasma Version: 6.0.4
KDE Frameworks Version: 6.2.0
Qt Version: 6.7.0
Kernel Version: 6.8.10-300.fc40.x86_64 (64-bit)
Graphics Platform: Wayland
Comment 3 Igor Kushnir 2024-06-07 11:19:59 UTC
The posted backtrace is incomplete (only 10 last stack frames).

The only backtrace containing Visitor::setTypeSize on my disk is the one discussed in https://invent.kde.org/kdevelop/kdevelop/-/merge_requests/210#note_156543 - this crash has been fixed before the merge request was merged. But maybe you hit another edge case. Or this could be a regression in Clang 18.

The only reported bug containing Visitor::setTypeSize is Bug 451856. Could be related.