Commit Graph

121 Commits

Author SHA1 Message Date
Marco Bubke
1e3f2eec8d Clang: Consolidate all ClangCompilerOptionsBuilder into one implementation
We used the same code in different but don't shared it. From a bug fixing
perspective it's actually not that smart.

Change-Id: Iaaffc883229e259ff77f95b5cf0a8f0d8b5117df
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
2016-12-15 10:18:15 +00:00
Nikolai Kosjar
3245a3d2f5 Clang: Soft assert valid instrinsics dir
We probably should add a message box for this in the master version.

Change-Id: Icc01eeb258445c361e7c6227e6bd768b9d16d350
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2016-11-24 13:57:17 +00:00
Nikolai Kosjar
6cf1f7968f Clang: Fix initial document parse with modified content
Reproduce with:

  1. Create a new class named Foo with the wizard.
  2. Close foo.h
  3. In foo.cpp, add some class member function.
  4. In foo.cpp, trigger the refactoring action "Add public Declaration"
     for the just defined member function. As a result, foo.h will be
     opened.
     ==> While the declaration was added, the header file is not yet
         reparsed with the new content - this can be verified by setting
         a custom color for "Function".

In this use case, the refactoring action opens the editor and
immediately modifies the document (RefactoringFile::apply).

Fix by sending the document content along for the very first
RegisterTranslationUnitForEditorMessage if the document was already
modified.

Change-Id: If20615a45b72dd0bef87e1870e403d0b277bc5d6
Reviewed-by: David Schulz <david.schulz@qt.io>
2016-11-23 11:50:39 +00:00
Nikolai Kosjar
2b9e9ebbfc Clang: Work around libclang not accepting not existing unsaved files
Feeding libclang with unsaved files (e.g. in-memory generated ui_*.h)
that do not exist on disk leads to regeneration of the preamble on every
parse/reparse/completion and thus renders the clang code model useless.

We could check the existence in the file system for every unsaved file
just before every parse/reparse/completion. Obviously this does not
scale (e.g. qtcreator.pro generates about 200 unsaves files) and would
also slow down the responsiveness of the completion, especially for the
dot-to-arrow correction case.

We could also set up a file system watcher. However, implementing the
"file got created" case is not trivial because QFileSystemWatcher does
not support it out of the box.

Instead, set up a custom include directory and create empty files in it
that represent the unsaved files and pass that include directory to
libclang as the last one. While this fixes the performance problems, it
also comes with at least two problems:

  * Because ui_*.h files are "relocated" to the same directory, two or
    more "foo.ui" in the same session will be problematic.

  * Because of the custom include directory, problems might arise for
    projects that include the ui_*.h as "some/relative/path/ui_foo.h"
    instead of "ui_foo.h". This should be the less common case.

Task-number: QTCREATORBUG-17245
Change-Id: I6e40e87c3ef095086eb22c972dd8c1a6459a8245
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
2016-11-22 12:21:14 +00:00
Denis Klychkov
36d4d01cd3 Clang: Take precompiled headers into account when parsing source files
Task-number: QTCREATORBUG-15590
Change-Id: Icbfce4ffd6e9f9802641d35d898fa1dc1c4c18ee
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
2016-11-16 09:10:14 +00:00
Nikolai Kosjar
df581265c3 Clang*: Workaround parsing mingw's <type_traits> with clang 3.9
...for -std=gnu++0x.

Define the unknown identifier/type "__float128" so at least the headers can be
parsed successfully. Of course this does not help for parsing client code
referencing that identifier, but this should be the less common case.

Task-number: QTCREATORBUG-17126
Change-Id: Id321311713029d8aa77e068b02361d86debfada6
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2016-10-18 15:07:15 +00:00
Nikolai Kosjar
57ac8d96c7 Clang: Avoid running into gcc/mingw intrinsics
Same as for the Clang Static Analyzer, so move the implementation into the base
class and use it.

This has gone unnoticed so far because it looks like that the error diagnostic
from the bug report can be extracted with libclang (as shown in the info bar),
but is not printed from libclang or clang.exe itself.

Change-Id: I5b714ba374c5fdefe234faf012a3515e96c9a08c
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2016-10-18 15:04:16 +00:00
Nikolai Kosjar
b0a49ca1c1 Clang: Fix parsing MSVC's crtdefs.h for 64 Bit
...by specifying the word width, as for the Clang Static Analyzer.

This has gone unnoticed so far because it looks like that the error diagnostic
from the bug report can be extracted with libclang (as shown in the info bar),
but is not printed from libclang or clang.exe itself.

Task-number: QTCREATORBUG-17130
Change-Id: Ia7a5ee3825c7211cdf80c2166a9eb454ce48cac1
Reviewed-by: David Schulz <david.schulz@qt.io>
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2016-10-18 15:03:52 +00:00
Nikolai Kosjar
f4994a5f76 CppTools: Always pass in header paths as native paths
Change-Id: I473c737107c14a4bc2c78b7c697eef02eb4bacff
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2016-10-17 13:19:55 +00:00
Nikolai Kosjar
6884ab080e ClangStaticAnalyzer: Fix path for intrinsics for clang toolchains
Ignore the include path for intrinsics coming from the toolchain. The
clang static analyzer comes with its own intrinsics and does not cope
well with intrinsics from other clang versions.

Move the relevant implementation from LibClangOptionsBuilder into the
base class so that ClangStaticAnalyzer profits from this, too.

Task-number: QTCREATORBUG-17102
Change-Id: Id9a28ddebb889c862939332dce888a80b3bb7e63
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2016-10-13 10:17:58 +00:00
Eike Ziller
c412e0bb2a Fix that clang static analyzer did not find built-in headers
Clang expects these to lie in "../lib/clang" relative to the clang
executable.

Change-Id: I216860876591dca1fd728e4b1e79b4b07c965620
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
2016-08-18 10:20:59 +00:00
Nikolai Kosjar
36e7f4541f Clang: Pass on file paths with native separators
libclang 3.8 seems to be sensitive to file paths separators [1]. On Windows,
this led to not updated document annotations and/or crashes after reparsing.

When passing file paths to libclang, convert to native separators.
When getting file paths from libclang, convert back.

This handles:
 * main file path
 * file paths of the unsaved files
 * -I<DIR> arguments, the resource path (for builtins) and the paths to the
   wrapped qt headers
 * included header files from libclang
 * source locations from libclang

Also, minimize the conversion in SourceLocation to a minimum by making
filePath() lazy.

[1] https://llvm.org/bugs/show_bug.cgi?id=28381

Change-Id: If5866f34a6fdc6b34b16c022d3988e8e6eae2a0a
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2016-07-04 13:08:03 +00:00
Nikolai Kosjar
e2e3be09e3 Clang: Enable exceptions explicitly
For some reason, clang 3.8.0 on Windows does not enable exceptions anymore,
which leads to parse errors in MSVC headers (reported upstream [1]).

With this change, we can finally parse main/mainwindow.cpp of a Qt Widgets
Application for a MSVC2015 Kit and libclang 3.8.0 without any error.

[1] https://llvm.org/bugs/show_bug.cgi?id=27324

Change-Id: I532ad4852a06318baf083d363378bc577b3c4309
Reviewed-by: Christian Kandeler <christian.kandeler@theqtcompany.com>
2016-04-13 07:13:25 +00:00
Nikolai Kosjar
4e0b55f673 Clang: Undefine language features as fix for MSVC2015/clang-3.8.0
This applies the following change for the clang code model, too.

  commit d13d179524
  Clang Static Analyzer: Workaround analyzing MSVC2015 projects with clang 3.8.0 II

Change-Id: Ia229d7e8b24c2e1c0a83d9a53c623ea1f79c4a06
Reviewed-by: Christian Kandeler <christian.kandeler@theqtcompany.com>
2016-04-12 14:54:06 +00:00
Nikolai Kosjar
5ff5211a25 Clang: Set -fms-compatibility-version explicitly
Infer the version from the _MSC_FULL_VER macro, so it cannot get out of sync
with that.

Adapt the analyzer to do the same.

Based on

  commit daf08d8702
  Clang Static Analyzer: Workaround analyzing MSVC2015 projects with clang 3.8.0

Change-Id: I9d34abdbe2c83fe271eadd8d051caad43aca6772
Reviewed-by: Christian Kandeler <christian.kandeler@theqtcompany.com>
2016-04-12 12:59:03 +00:00
Nikolai Kosjar
276f4c489c Clang: Explicitly set the target triple
As for the analyzer, this makes us independent of the default triple and will
most likely reduce the maintenance - e.g. the target implies certain internal
command line arguments, we will profit from added ones.

This fixes parsing of mingw headers with the clang code model.

Change-Id: I722b981125a80fac5f62a7af40a83ecdd7bbf811
Reviewed-by: Christian Kandeler <christian.kandeler@theqtcompany.com>
2016-04-11 10:16:34 +00:00
Tobias Hunger
397e7f4843 Update License according to agreement with Free Qt Foundation
* Update files in src/plugins

Change-Id: Ia5d77fad7d19d4bb3498e78661982f68729adb22
Reviewed-by: Tobias Hunger <tobias.hunger@theqtcompany.com>
2016-01-19 15:57:01 +00:00
Marco Bubke
ddd1d4c9cc CppTools: Remove cpptools/cppprojects.[h|cpp]
Change-Id: Ida0e8552d371972c141cf561b28667f4428c6fff
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
2016-01-13 14:47:27 +00:00
Nikolai Kosjar
ca63359386 CppTools/Clang: Clean-up of includes
Change-Id: I0ba340dcf0ee23e61588f17262d07e7088751836
Reviewed-by: Marco Bubke <marco.bubke@theqtcompany.com>
2015-12-16 13:15:38 +00:00
Nikolai Kosjar
5d1e894ef5 Clang: Remove left-over logging category
Change-Id: I6724d045e6d404f518d579bd10abdea47b8fa697
Reviewed-by: Marco Bubke <marco.bubke@theqtcompany.com>
2015-12-08 15:42:36 +00:00
Nikolai Kosjar
5f98b8ec24 Clang: Remove PchManager
...which is the last dependency to libclang from the plugin.

Change-Id: I173ee7e9621912ec88706b4cf62db2b1dbcf7610
Reviewed-by: Marco Bubke <marco.bubke@theqtcompany.com>
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
2015-11-30 11:03:51 +00:00
Nikolai Kosjar
82cf0e60fb Clang: Fix include paths for MSVC toolchains
Prevent libclang from using any builtin includes paths or any standard system
directories. The project manager provides us all the necessary information.

Task-number: QTCREATORBUG-15345
Change-Id: I70e2dafea8d049a9b7a32b24ce2d4ce3dac2cd3b
Reviewed-by: Marco Bubke <marco.bubke@theqtcompany.com>
2015-11-18 15:11:42 +00:00
Nikolai Kosjar
d8f119c8a2 Clang: Allow to provide extra command line options
This can be used to experiment with clang options that e.g. affect
diagnostics.

Changes take effect on editor re-open.

Change-Id: Ie46d0ff085a3700a748dbcf4b94b93b0bf9c4642
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@theqtcompany.com>
Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
2015-11-11 15:14:56 +00:00
Nikolai Kosjar
4d1a1981a8 CppTools: CompilerOptionsBuilder takes project part by reference
...since it assumes a project part != 0 and does not participate in
ownership.

Change-Id: Ia9c1eca52776990576a2dac61e9144234b04c59c
Reviewed-by: Erik Verbruggen <erik.verbruggen@theqtcompany.com>
2015-11-11 09:51:19 +00:00
Nikolai Kosjar
d06aee195f Clang: Remove pointless function
Change-Id: Ib4cc26ca39f7ced993a9a4c142208c377d940719
Reviewed-by: Erik Verbruggen <erik.verbruggen@theqtcompany.com>
2015-11-06 11:32:42 +00:00
Nikolai Kosjar
c45f08cdae Clang: Rename isProjectPartValid to isProjectPartLoaded
Change-Id: Ib20700ebb7142cfa9e75edff3b21410fd3bdab05
Reviewed-by: Marco Bubke <marco.bubke@theqtcompany.com>
2015-10-14 10:12:08 +00:00
Marco Bubke
250c8d662b Clang: Add UpdateTranslationUnitsForEditorMessage
If an editor is changing all translation units independent of their project
part they must be updated too. So we introduce a new message to update all
translation units with the same file path.

Change-Id: I70d0ea2bbca9fa880111ff7219573e54f3277026
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
2015-10-13 14:03:11 +00:00
Marco Bubke
27991f2c8f Clang: Add -Wno-shadow
Change-Id: Icc6b08a0eea026d3126c236a37318eaee9f3c0e8
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
2015-10-01 13:21:58 +00:00
Marco Bubke
bdd82b7a4c Clang: Add -Wno-documentation
Change-Id: Ie0e4babe29934d9b90d24bb4c966d6ed6ba3c238
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
2015-10-01 13:21:52 +00:00
Marco Bubke
893e2279b3 Clang: Add -Wno-gnu-zero-variadic-macro-arguments
It's actually tricky because the standard says that zero arguments should
be not possible in variadic macros but certain compilers support it and we
using it in the logging framework.

Change-Id: Ib9e1832748e8c57f149dfcfefead9618fd5e51f4
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
2015-10-01 13:07:22 +00:00
Marco Bubke
f31e02be3c Clang: Add -Wno-global-constructors
Change-Id: I77f89e15142ae5e0b6484bc02aef7b9733ea8c1f
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
2015-10-01 13:07:17 +00:00
Marco Bubke
ecce6cd12f Clang: Add -Wno-exit-time-destructors
Change-Id: Ibf6b5c9a791e0fad49939c2a352b7eaa064f2376
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
2015-10-01 13:07:12 +00:00
Marco Bubke
54f505b834 Clang: Disable warning newline-eof
Change-Id: I9a773d70485f3e534e7fabdde3bd5936002c851c
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
2015-10-01 13:07:07 +00:00
Marco Bubke
a9193243b9 Clang: Don't show warnings for missing prototypes in C++
Change-Id: I895ec7424e04d1f0d465f008ee4a5b5ff76a4906
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
2015-09-23 15:41:30 +00:00
Eike Ziller
c868b9f3ed Merge remote-tracking branch 'origin/3.5'
Change-Id: Ife5fdcd71b0adc99d4297a28a64515e9e93d7864
2015-09-04 09:19:28 +02:00
Nikolai Kosjar
169556db2f C++: Fix crash after triggering completion and closing editor
Fix use-after-free for the following case:
  1. Open an editor
  2. Trigger a long processing completion
     (e.g. simulate with QThread::msleep in
      CppCompletionAssistInterface::getCppSpecifics)
  3. ...and immediately close the editor (e.g. with Ctrl+W)
  4. Wait until it crashes.

The completion thread relied on the BuiltinEditorDocumentParser object,
which is deleted once the editor is closed. Fixed by sharing the
ownership of that object between the *EditorDocumentProcessor and the
completion assist interface.

This case came up when doing tests for the bug report below.

Task-number: QTCREATORBUG-14991
Change-Id: I0b009229e68fc6b7838740858cdc41a32403fe6f
Reviewed-by: David Schulz <david.schulz@theqtcompany.com>
2015-09-02 12:37:23 +00:00
Marco Bubke
e8e45ca102 Clang: Don't show a warning for unused macros anymore
Change-Id: Ia816476ed577d7060d752e74e5be2c2f1ebb7f12
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
2015-09-01 10:04:19 +00:00
Marco Bubke
b278dc87ca Clang: Add diagnostics
Diagnostics are now moved to the clang backend process. Fixits are
supported too.

Change-Id: I20faacf466bbf78dec479220c3d7b336a47bc453
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
2015-08-31 14:59:16 +00:00
Marco Bubke
ec4d002857 Clang: Rename command in message
Change-Id: I1e2671d15b0db3c670b86dd0d4bed5ee09e866f1
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
2015-08-25 12:54:27 +00:00
Nikolai Kosjar
2bc96c7621 Clang: Fix threading issue with QRegExp
exactMatch() is declared const, but is actually not. Replace with
QRegularExpression.

Change-Id: Ib9d9c091de1cd81d81671c19a76cada8777ff287
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
2015-08-17 08:19:59 +00:00
Nikolai Kosjar
039d9309a9 Clang: Ignore include dirs matching lib/clang/x.y/include
On OS X the clang versioning is different.

This completes

    775661fafb
    Clang: Ignore clang include directories from the toolchain

Task-number: QTCREATORBUG-14856
Change-Id: Ib93ce9fcf18a3c8693f9f2af8075eeef8b93fa32
Reviewed-by: Marco Bubke <marco.bubke@theqtcompany.com>
2015-08-12 15:59:51 +00:00
Nikolai Kosjar
775661fafb Clang: Ignore clang include directories from the toolchain
Change-Id: I23a91f1511fad81de0abdd8c8d47dc23f0e0ae43
Task-number: QTCREATORBUG-14856
Reviewed-by: Erik Verbruggen <erik.verbruggen@theqtcompany.com>
2015-08-06 08:05:24 +00:00
Nikolai Kosjar
4f7649633c Clang: Free us from specific Qt versions
More precisely, free us from specific Q_MOC_RUN/QT_NO_META_MACROS code
paths in QtCore/qobjectdefs.h.

In order to track signals and slots we provided custom definitions of
e.g. "Q_SIGNAL" by including qt5-qobjectdefs-injected.h with "-include".
We also had to ensure that those macros were not overwritten by Qt's
qobjectdefs.h, which we did by defining QT_NO_META_MACROS. However, this
came with a cost: we needed to replicate all the other macro definitions
in the Q_MOC_RUN/QT_NO_META_MACROS code path, e.g. Q_INTERFACES. This
bound us to specific versions of qobjectdefs.h and occasionally we had
to adapt (see change 4eafa2e02b).

The new approach wraps Qt's qobjectdefs.h with the help of
"include_next". In the wrapper header, we only redefine what is
necessary.

The "include_next" directive is originally a GNU extension. Clang seems
to support it unconditionally, as [1] implicitly states.

[1] http://clang.llvm.org/docs/LanguageExtensions.html#include-file-checking-macros

Change-Id: Ic1a263f94b178349cb32bfdbb074ad5e6e0761ee
Reviewed-by: Christian Kandeler <christian.kandeler@theqtcompany.com>
Reviewed-by: Erik Verbruggen <erik.verbruggen@theqtcompany.com>
2015-07-27 13:12:41 +00:00
Nikolai Kosjar
09b405d11e Clang: Extract some functions in LibClangOptionsBuilder
...makes the high-level function build() less noisy.

Change-Id: Ib09fba315845a604166489fd400d0be14e16fc23
Reviewed-by: Christian Kandeler <christian.kandeler@theqtcompany.com>
2015-07-27 12:26:41 +00:00
Nikolai Kosjar
420bc69739 CppTools: Use project part ids instead of file paths
File paths are not unique since e.g. each qbs group in a file is mapped
to a project part.

Change-Id: I7df3f224dd23046b869f2588b8a34eb26cfc0b1a
Reviewed-by: Marco Bubke <marco.bubke@theqtcompany.com>
2015-07-20 09:49:14 +00:00
Nikolai Kosjar
418fc32f6a Clang: Do not call DocumentManager::modifiedDocuments() from worker thread
This is unsafe.

Change-Id: I8ac075a7289afa0d84785e37b1325d186a153000
Reviewed-by: Erik Verbruggen <erik.verbruggen@theqtcompany.com>
2015-07-10 14:04:19 +00:00
Nikolai Kosjar
70bc5e842c CppTools: Add toolchain type to project part and use it
Making CompilerOptionsBuilder to use the toolchain from the project part
simplifies its public API, but following the code paths initiated by
ClangCodeModel and ClangStaticAnalyzer gets harder, so better enable the
separation of those by making CompilerOptionsBuilder a base class.

Change-Id: I0a6bb3f8323ba09b88135a7f9d1ef967331a8ff0
Reviewed-by: Christian Kandeler <christian.kandeler@theqtcompany.com>
2015-06-29 09:14:48 +00:00
Nikolai Kosjar
dcccb4cb8d CppTools: Use CompilerOptionsBuilder as an object
Makes the client code more readable.

Change-Id: Ie98ba93c758643039d3ebdc7550b1c4ac9473298
Reviewed-by: Marco Bubke <marco.bubke@theqtcompany.com>
Reviewed-by: Christian Kandeler <christian.kandeler@theqtcompany.com>
2015-06-26 07:23:38 +00:00
Nikolai Kosjar
23b8a3b2e8 Clang: Use completion through backend process
This makes us independent of libclang crashes for completion.
Re-parsing for highlighting still happens in the Qt Creator process.

Run in verbose mode:
    qtc.clangcodemodel.ipc=true

Run tests:
    -test "ClangCodeModel"

Task-number: QTCREATORBUG-14108
Task-number: QTCREATORBUG-12819
Change-Id: Id3e95bd2afdb6508bbd1d35fddc69534a909b905
Reviewed-by: Marco Bubke <marco.bubke@theqtcompany.com>
2015-06-10 10:15:40 +00:00
Nikolai Kosjar
e488f10c7f Clang: Fix providing clang directory with intrinsics
Opening a main.cpp of a Qt Widget Application project that is configured
with a GCC toolchain leads to errors [1] like

    /usr/lib/gcc/x86_64-linux-gnu/4.8/include/ia32intrin.h:41:10: \
    error: use of undeclared identifier '__builtin_ia32_bsrsi'

due to a wrong determination of the clang directory with intrinsics. The
directory was determined as

    $${LLVM_LIBDIR}/clang/$${LLVM_VERSION}/include

whereas $LLVM_VERSION was extracted as e.g. "3.5" from 'llvm-config
--version' instead of "3.5.0".

The path of clang intrinsics dir shipped with Qt Creator (as package)
does also match this version scheme:

    $QTC_INSTALL_DIR/share/qtcreator/cplusplus/clang/3.4.2/include

[1] Visible with qtc.clangcodemodel.verboserun=true

Change-Id: I1061912eef437a9889987e638915d2fabe208011
Reviewed-by: hjk <hjk@theqtcompany.com>
Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
2015-04-20 12:41:14 +00:00