summaryrefslogtreecommitdiff
path: root/doc/src/analyze/creator-clang-static-analyzer.qdoc
blob: c4468ef038996ef096cd641cc8599f7db83479db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/****************************************************************************
**
** Copyright (C) 2019 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt Creator documentation.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Free Documentation License Usage
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
** Foundation and appearing in the file included in the packaging of
** this file. Please review the following information to ensure
** the GNU Free Documentation License version 1.3 requirements
** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
**
****************************************************************************/

// **********************************************************************
// NOTE: the sections are not ordered by their logical order to avoid
// reshuffling the file each time the index order changes (i.e., often).
// Run the fixnavi.pl script to adjust the links to the index order.
// **********************************************************************

/*!
    \contentspage index.html
    \previouspage creator-running-valgrind-remotely.html
    \page creator-clang-tools.html
    \nextpage creator-heob.html

    \title Using Clang Tools

    \QC integrates the following Clang tools for finding problems in C, C++, and
    Objective-C source code by using static analysis:

    \list

        \li \l{https://clang.llvm.org/extra/clang-tidy/}{Clang-Tidy}, which
            provides diagnostics and fixes for typical programming errors,
            such as style violations or interface misuse.

        \li \l{https://github.com/KDE/clazy/blob/master/README.md}{Clazy}, which
            helps Clang understand Qt semantics. It displays Qt related compiler
            warnings, ranging from unnecessary memory allocation to misuse of
            API and provides refactoring actions for fixing some of the issues.

    \endlist

    \note The Clang static analyzer checks are a part of Clang-Tidy. To use
    the checks you must create a custom configuration for the Clang tools and
    enable them for Clang-Tidy.

    Clang tools are delivered and installed with \QC, and therefore you do not
    need to set them up separately.

    \section1 Running Clang Tools

    To run the Clang tools to analyze an open project:

    \list 1

        \li Select \uicontrol Analyze > \uicontrol {Clang-Tidy and Clazy}.

            \image qtcreator-files-to-analyze.png "Analyzer Configuration dialog"

        \li In the \uicontrol General group, select \uicontrol {Custom Settings}
            to modify the analyzer configuration.

        \li To build the project before running the Clang tools, select the
            \uicontrol {Build the project before analysis} check box. The Clang
            tools do not require the project to be built before analysis, but
            they might display misleading warnings about files missing that are
            generated during the build. For big projects, not building the
            project might save some time.

        \li In the \uicontrol {Diagnostic configuration} field, select a Clang
            configuration in the list of pre-defined configurations (1). For
            more information about creating a custom configuration, see
            \l {Configuring Clang Tools}.

        \li In the \uicontrol {Files to Analyze} group, select the files to
            apply the checks to.

        \li Select \uicontrol Analyze to start the checks.

    \endlist

    If you select \uicontrol Debug in the mode selector to open the
    \uicontrol Debug mode and then select \uicontrol {Clang-Tidy and Clazy},
    you must select the \inlineimage qtcreator-analyze-start-button.png
    (\uicontrol Start) button to open the \uicontrol {Analyzer Configuration}
    dialog.

    The found issues are displayed in the \uicontrol {Clang-Tidy and Clazy}
    view:

    \image qtcreator-clang-tools.png "Clang-Tidy and Clazy view"

    Double-click an issue to move to the location where the issue appears in
    the code editor.

    If a fixit exists for an issue, you can select the check box next to the
    issue to schedule it for fixing. You can see the status of the issue by
    hovering the mouse pointer over the icon next to the check box.

    \section1 Configuring Clang Tools

    To configure Clang diagnostics globally for Clang tools:

    \list 1

        \li Select \uicontrol Tools > \uicontrol Options > \uicontrol Analyzer >
            \uicontrol {Clang Tools}.

            \image qtcreator-clang-tools-options.png "Clang Tools options tab"

        \li To build the project before running the Clang tools, select the
            \uicontrol {Build the project before analysis} check box. The Clang
            tools do not require the project to be built before analysis, but
            they might display misleading warnings about files missing that are
            generated during the build. For big projects, not building the
            project might save some time.

        \li In the \uicontrol {Simultaneous processes} field, select the number
            of processes to run simultaneously to make the analysis faster on
            multi-core processors.

        \li In the \uicontrol {Diagnostic Configuration} group, select
            \uicontrol Manage to create or edit a custom configuration.

        \li Select \uicontrol Copy to create a custom Clang configuration.

            \image qtcreator-diagnostics-configuration.png "Diagnostics Configuration dialog"

        \li In the \uicontrol {Diagnostic configuration name} field, give the
            configuration a name, and then select \uicontrol OK.

        \li In the \uicontrol Clang tab, select the
            \uicontrol {Use diagnostic flags from the build system} check box
            to forward diagnostic flags, such as warning flags, from the build
            system to the Clang code model for displaying annotations in the
            code editor.

        \li In the \uicontrol {Clang-Tidy} tab, select
            \uicontrol {Select Checks} to select the checks to perform,
            \uicontrol {Use .clang-tidy Config File} to read them from a
            Clang-Tidy configuration file, or \uicontrol Disable to disable
            them.

            \image qtcreator-clang-tidy.png "Clang-Tidy tab"

        \li Select the \uicontrol {Web Page} link to view more
            information about the available checkers in the
            \l{https://clang-analyzer.llvm.org/available_checks.html}
            {Clang Static Analyzer documentation}.

        \li To edit the selected check as plain text, select
            \uicontrol {Edit Checks as String}.

        \li In the \uicontrol Clazy tab, select the level of Clazy
            checks to perform.

            \image qtcreator-clazy.png "Clazy tab"

        \li In the \uicontrol {Topic Filter} field, select a topic to view
            only checks related to that area in the \uicontrol Checks field.

        \li To view all checks again, select \uicontrol {Reset to All}.

        \li To view more information about the checks online, select the
            \uicontrol {Web Page} links next to them.

    \endlist

    To suppress diagnostics, select \uicontrol {Suppress This Diagnostic} in the
    context menu. To view the suppression list for a project and to remove
    diagnostics from it, select \uicontrol Projects >
    \uicontrol {Project Settings} > \uicontrol {Clang Tools}.

    \section2 Selecting Clazy Check Levels

    The Clazy checks are divided into levels from 0 to 3. The checks at level 0
    are very stable and provide hardly any false positives, while the checks at
    level 3 can be considered experimental. You can select the checks to perform
    at each level. To include the checks from the lower levels automatically,
    select the \uicontrol {Enable lower levels automatically} check box.

*/