Qt Creator Clang Code Model
- 1 Debugging
- 2 Related Environment Variables
- 3 Libclang
- 4 Clang Plugins
- 5 Backport candidates for Qt Creator 4.7
- 6 Backport candidates for Qt Creator 4.6
With the following invocation debugging output will be generated:
export QT_LOGGING_RULES=qtc.clang*=true export LIBCLANG_TIMING=1 ./qtcreator
Windows (start DebugView in advance to see the output):
set QT_LOGGING_RULES=qtc.clang*=true set LIBCLANG_TIMING=1 qtcreator.exe
The debugging output contains among others:
- The IPC messages send/received
- Output of libclang while parsing
Internal command line
The debugging output from above will contain all the command line options that are passed on to libclang, which is enough for most cases.
However, to see also the resulting internal command line of libclang run:
- Restart Qt Creator with QTC_CLANG_NO_DIAGNOSTIC_CHECK=1 (>= Qt Creator 4.5)
- Switch to projects mode and there to the "Clang Code Model"
- Copy some warning configuration by clicking on "Copy...", give it a name like "Debug"
- Replace all the options from the copied configuration with "-###"
- Close and re-open the editor document - the new debugging output will contain also the internal command line
Note that libclang/clangbackend will crash afterwards, so do not forget to switch back to a sane warning configuration.
Related Environment Variables
- QTC_ENABLE_CLANG_LIBTOOLING - Build against Clang's C++ libs; the ClangFormat and ClangRefactoring plugin and dependencies will be build.
- LIBCLANG_TIMING - Timings from libclang for parse / reparse / preamble generation / completion.
- QTC_CLANG_ENABLE_STACKTRACES - For debugging. Enables the clang stack trace printer on a crash. Might deadlock clangbackend.
- QTC_CLANG_NO_DIAGNOSTIC_CHECK - Avoid validation of warning configuration (>= Qt Creator 4.5)
- QTC_CLANG_NO_SUPPORTIVE_TRANSLATIONUNIT - Use only one translation unit per document.
- QTC_CLANG_NO_ALIVE_TIMER - Simplifies debugging in certain cases.
- QTC_CLANG_FORCE_VERBOSE_ALIVE - Simplifies debugging in certain cases.
libclang is used inside clangbackend to provide code model features
Linux and Mac:
libclang is built with the same compilers as Qt Creator ("Clang 7.0 (Apple)" for macOS, and GCC 5.3 from RHEL (which turns on old ABI compatibility with _GLIBCXX_USE_CXX11_ABI=0 by default) on Linux)
Currently libclang is built with optimized MinGW compiler for all Qt Creator versions. More information about Windows builds: Build libclang on Windows
Minimal libclang installation that Qt Creator can use
The following targets are sufficient for this:
install-libclang install-libclang-headers install-clang-headers install-llvm-config
Clang plugins support is already in last QtCreator release (4.6).
ClangTidy can be hardly transformed into dynamic plug-in (at least on Windows) and does not support plugins as a standalone tool. Therefore ClangTidy and Clazy are linked statically into libclang and clang driver (last one is in progress) in our custom clang builds.
Plugins usage significantly affects libclang performance so set up your settings (Tools->Options->C++->Code Model->Clang Plugins) wisely:
level1 adds 50% to the parse/re-parse time, level0 adds only 25%
clang-diagnostic-*,llvm-*,misc-* add 200% to the original libclang parse/re-parse times
Backport candidates for Qt Creator 4.7
Backport candidates for Qt Creator 4.6
Qt Creator 4.6 will ship with LLVM/Clang 5.
The following changes from LLVMt/Clang trunk might be worthwhile to backport.
Crash / Parsing
[Sema] Fix crash in unused-lambda-capture warning for VLAs
Crash / Completion (excluded because it leads to crashes in clang tests)
Fixed a crash in code completion.
Fixes crash when requesting completion at e.g. int (*foo(int a))(flo<CURSOR>
Crash / Completion
[Lex] Fix crash on code completion in comment in included file.
Crash / Static Analyzer
[analyzer] Fix a crash on C++17 AST for non-trivial construction into a trivial brace initializer.
Crash / Reparse, MSVC 15.5 specific
Correctly handle line table entries without filenames during AST serialization
Fixes crash during a reparse.
[PCH] Serialize skipped preprocessor ranges
This fixes, for example, libclang's clang_getSkippedRanges returning zero ranges after reparsing a translation unit.
Affects highlighting of preprocessor ranges.
Minor / AST Access
[libclang] Fix cursors for in-class initializer of field declarations
Fixes AST access to initializers of class members. Affects mostly semantic highlighting and highlighting of local uses.
Minor / AST Access
[libclang] Fix cursors for functions with trailing return type
Minor / AST properties
[libclang] Add support for checking abstractness of records
Would need https://codereview.qt-project.org/#/c/211497/ on Qt Creator side.
[DeclPrinter] Honor TerseOutput for constructors
Avoids printing member initialization list and body for constructor.
Fix utf8 specific highlighting issues
[libclang] Add function to get the buffer for a file
Together with https://codereview.qt-project.org/#/c/212972/ fixes highlighting
Fix MSVC related highlighting issues
[libclang] Only mark CXCursors for explicit attributes with a type
Some classes have totally broken highlighting (like classes inside texteditor.cpp)
Fix templated type alias completion when using global completion cache
Fixes completion involving templated type alias.
https://reviews.llvm.org/D35355 (with slight update)
Fix overloaded static functions in SemaCodeComplete
Happens when static function is accessed via the class variable.
That leads to incorrect overloads number because the variable is considered as the first argument.
Fix overloaded static functions for templates
Apply almost the same fix as D36390 but for templates