https://bugs.kde.org/show_bug.cgi?id=444693

            Bug ID: 444693
           Summary: Crash on assert in ClangHelpers::buildDUChain when
                    casting ParsingEnvironmentFile
           Product: kdevelop
           Version: git master
          Platform: Neon Packages
                OS: Linux
            Status: REPORTED
          Severity: crash
          Priority: NOR
         Component: Language Support: CPP (Clang-based)
          Assignee: kdevelop-bugs-n...@kde.org
          Reporter: jonathan.ver...@matfyz.cz
  Target Milestone: ---

I recently get quite consistent crashes (without clearing the cache) in
`ClangHelpers::BuildDUChain`
on line 168 asserting on `envFile` with the following backtraces (removed the
irrelevant parts):

#5  0x00007fff44c253f4 in ClangHelpers::buildDUChain(void*, QMultiHash<void*,
Import> const&, ParseSession const&, QFlags<KDevelop::TopDUContext::Feature>,
QHash<void*, KDevelop::ReferencedTopDUContext>&, QHash<KDevelop::IndexedString,
KDevelop::ModificationRevision> const&, KDevelop::IndexedString const&,
ClangIndex*, std::function<bool ()> const&)
    (file=0x7ffea000b4d0, imports=QMultiHash<void *, Import> (size = 0),
session=..., features=..., includedFiles=QHash<void *,
KDevelop::ReferencedTopDUContext> (size = 1) = {...},
unsavedRevisions=QHash<KDevelop::IndexedString, KDevelop::ModificationRevision>
(size = 5) = {...}, parseDocument=..., index=0x55555a9504e0, abortFunction=...)
at
/home/jonathan/zdroj/clones/kdevelop/plugins/clang/duchain/clanghelpers.cpp:168
#6  0x00007fff44ce0557 in
ClangParseJob::run(QSharedPointer<ThreadWeaver::JobInterface>,
ThreadWeaver::Thread*) (this=0x555560618090)
    at /home/jonathan/zdroj/clones/kdevelop/plugins/clang/clangparsejob.cpp:341
#7  0x00007ffff24a5def in
ThreadWeaver::IdDecorator::run(QSharedPointer<ThreadWeaver::JobInterface>,
ThreadWeaver::Thread*)
    (this=<optimized out>, self=..., thread=0x55556083fdd0) at
/usr/include/c++/9/bits/atomic_base.h:318


The `envFile` is the result of dynamic casting
`context->parsingEnvironmentFile().data()` to `ClangParsingEnvironmentFile*`.
This cast
does not go through, because the environment file is actually a
`StandardParsingEnvironmentFile` (with language CMake).
This is not surprising, given that the first parameter to `buildDUChain` is a
`CXFile` pointing to 

/home/jonathan/zdroj/clones/kdevelop/build/plugins/clangtidy/tests/CMakeFiles/test_clangtidyparser.dir/cmake_clean.cmake

i.e. a **cmake** file (!). The parseDocument parameter, on the other hand,
points to

/home/jonathan/zdroj/clones/kdevelop/plugins/custom-buildsystem/kcm_custombuildsystem.h

the contents of session.environment are as follows:

(const ClangParsingEnvironment &) @0x7fff0fffe0b0: {
  <KDevelop::ParsingEnvironment> = {
    _vptr.ParsingEnvironment = 0x7fff44ccb840 <vtable for
ClangParsingEnvironment+16>
  }, 
  members of ClangParsingEnvironment:
  m_projectPaths = QVector<KDevelop::Path> (size = 4) = {
    [0] = ("home", "jonathan", "zdroj", "clones", "kdev-python"),
    [1] = ("home", "jonathan", "zdroj", "clones", "kdev-python", "build"),
    [2] = ("home", "jonathan", "zdroj", "clones", "kdevelop"),
    [3] = ("home", "jonathan", "zdroj", "clones", "kdevelop", "build")
  },
  m_includes = QVector<KDevelop::Path> (size = 0),
  m_frameworkDirectories = QVector<KDevelop::Path> (size = 0),
  m_defines = QMap<QString, QString> (size = 0),
  m_pchInclude = ,
  m_workingDirectory = ,
  m_tuUrl = {
    m_index = 2414975
  },
  m_quality = ClangParsingEnvironment::Unknown,
  m_parserSettings = {
    parserOptions = "  "
  }
}

I am very confused. Why is the `ClangHelpers::buildDUChain` even run for a
CMakeFile?? Why is the `parseDocument` a completely
unrelated header file???

(Note that
ICore::self()->languageController()->languagesForUrl(path.toUrl()).first()->name()
correctly returns "CMake" !!!)

Also note that, in `ClangParseJob::run`, `d_ptr->url.str() ==
"/home/jonathan/zdroj/clones/kdevelop/plugins/custom-buildsystem/kcm_custombuildsystem.h"`,
so the parse job was started for a header file. 

But the translation unit for this file
(`clang()->index()->translationUnitForUrl(d_ptr->url).str()`) seems to be the
completely unrelated 
cmake file 

/home/jonathan/zdroj/clones/kdevelop/build/plugins/clangtidy/tests/CMakeFiles/test_clangtidyparser.dir/cmake_clean.cmake

Why???

I have to go to sleep now, will try to investigate more later.

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to