Skip to content

Commit 68bf94a

Browse files
authored
Fix #15221 (Deprecate the clang import) (#9031)
1 parent e0596d3 commit 68bf94a

7 files changed

Lines changed: 45 additions & 40 deletions

File tree

‎cli/cmdlineparser.cpp‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1793,13 +1793,8 @@ void CmdLineParser::printHelp() const
17931793
" incomplete info.\n"
17941794
" --checkers-report=<file>\n"
17951795
" Write a report of all the active checkers to the given file.\n"
1796-
" --clang=<path> Experimental: Use Clang parser instead of the builtin Cppcheck\n"
1797-
" parser. Takes the executable as optional parameter and\n"
1798-
" defaults to `clang`. Cppcheck will run the given Clang\n"
1799-
" executable, import the Clang AST and convert it into\n"
1800-
" Cppcheck data. After that the normal Cppcheck analysis is\n"
1801-
" used. You must have the executable in PATH if no path is\n"
1802-
" given.\n"
1796+
" --clang=<path> Deprecated: Use Clang parser instead of the builtin Cppcheck\n"
1797+
" parser. This option will be removed in Cppcheck 2.27.\n"
18031798
" --config-exclude=<dir>\n"
18041799
" Path (prefix) to be excluded from configuration\n"
18051800
" checking. Preprocessor configurations defined in\n"

‎gui/projectfile.ui‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,8 +472,11 @@
472472
</item>
473473
<item>
474474
<widget class="QRadioButton" name="mBtnClangParser">
475+
<property name="enabled">
476+
<bool>false</bool>
477+
</property>
475478
<property name="text">
476-
<string>Clang (experimental)</string>
479+
<string>Clang (this feature is deprecated; this option will be removed in 2.27)</string>
477480
</property>
478481
</widget>
479482
</item>

‎lib/cppcheck.cpp‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,16 @@ unsigned int CppCheck::checkClang(const FileWithDetails &file)
683683
{
684684
// TODO: clear exitcode
685685

686+
// #15221 - clangimport is deprecated and will be removed
687+
{
688+
ErrorMessage errmsg;
689+
errmsg.callStack.emplace_back(file.spath(), 1, 1);
690+
errmsg.setmsg("clang import is deprecated, it will be removed in 2.27");
691+
errmsg.severity = Severity::information;
692+
errmsg.id = "clangimport";
693+
mErrorLogger.reportErr(errmsg);
694+
}
695+
686696
if (mSettings.checks.isEnabled(Checks::unusedFunction) && !mUnusedFunctionsCheck)
687697
mUnusedFunctionsCheck.reset(new CheckUnusedFunctions());
688698

‎man/manual-premium.md‎

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -150,18 +150,6 @@ Typically a `compile_commands.json` contains absolute paths. However no matter i
150150
- a file with relative path `test1.cpp` can be checked.
151151
- a file with relative path `test/somefile.cpp` is not checked
152152

153-
### Clang parser (experimental)
154-
155-
By default Cppcheck uses an internal C/C++ parser. However there is an experimental option to use the Clang parser instead.
156-
157-
Install `clang`. Then use Cppcheck option `--clang`.
158-
159-
Cppcheck executes clang with the -ast-dump option, imports the output, converts it to Cppcheck's internal format, and then
160-
performs standard analysis.
161-
162-
You can also pass a custom Clang executable to the option by using for example `--clang=clang-10`. You can also pass it
163-
with a path. On Windows it will append the `.exe` extension unless you use a path.
164-
165153
## Severities
166154

167155
The possible severities for messages are:

‎man/manual.md‎

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -151,18 +151,6 @@ Typically a `compile_commands.json` contains absolute paths. However no matter i
151151
- a file with relative path `test1.cpp` can be checked.
152152
- a file with relative path `test/somefile.cpp` is not checked
153153

154-
### Clang parser (experimental)
155-
156-
By default Cppcheck uses an internal C/C++ parser. However there is an experimental option to use the Clang parser instead.
157-
158-
Install `clang`. Then use Cppcheck option `--clang`.
159-
160-
Cppcheck executes clang with the -ast-dump option, imports the output, converts it to Cppcheck's internal format, and then
161-
performs standard analysis.
162-
163-
You can also pass a custom Clang executable to the option by using for example `--clang=clang-10`. You can also pass it
164-
with a path. On Windows it will append the `.exe` extension unless you use a path.
165-
166154
## Severities
167155

168156
The possible severities for messages are:

‎releasenotes.txt‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11

22
Release Notes for Cppcheck 2.23
33

4+
Options:
5+
- Rules: The PCRE library that we used is end-of-life. We have switched to PCRE2 instead. Existing rule files
6+
will hopefully work without changes.
7+
- The --clang option has been deprecated, it will be removed in Cppcheck 2.27
8+
49
Major bug fixes & crashes:
510
-
611

@@ -22,8 +27,8 @@ Import project:
2227
Infrastructure & dependencies:
2328
- Added arm64 platform files arm64-windows.xml, arm64-linux.xml and arm64-macos.xml (Apple Silicon).
2429
These describe the default setup for that OS. The arm64-wchar_t2.xml and arm64-wchar_t4.xml files are kept.
25-
- The rules feature (HAVE_RULES) now uses PCRE2 instead of the discontinued PCRE library. Existing rule patterns
26-
and rule files work unchanged. On Windows the Visual Studio project now expects pcre2-8.lib and pcre2.h in externals.
30+
- The rules feature (HAVE_RULES) now uses PCRE2 instead of the discontinued PCRE library. On Windows the
31+
Visual Studio project now expects pcre2-8.lib and pcre2.h in externals.
2732

2833
Other:
2934
-

‎test/cli/clang-import_test.py‎

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import subprocess
77
import sys
88
import pytest
9-
from testutils import cppcheck, assert_cppcheck
9+
from testutils import cppcheck
1010

1111
try:
1212
# TODO: handle exitcode?
@@ -20,6 +20,19 @@
2020
pytest.skip(allow_module_level=True)
2121

2222

23+
__DEPRECATION_MSG = 'information: clang import is deprecated, it will be removed in 2.27 [clangimport]'
24+
25+
26+
# #15221 - clang import is deprecated; check the message and return the remaining stderr lines
27+
def __check_deprecation(stderr, filename):
28+
lines = stderr.splitlines()
29+
assert len(lines) >= 3, lines
30+
assert lines[0] == '{}:1:1: {}'.format(filename, __DEPRECATION_MSG), lines
31+
# the message is followed by the code snippet and the caret
32+
assert lines[2] == '^', lines
33+
return lines[3:]
34+
35+
2336
def __get_debug_section(title, stdout):
2437
s = re.sub(r'0x[0-9a-fA-F]+', '0x12345678', stdout)
2538
s = re.sub(r'nestedIn: Struct', 'nestedIn: Class', s)
@@ -125,7 +138,10 @@ def test_log(tmpdir):
125138
'Checking {} ...'.format(test_file).replace('\\', '/'),
126139
]
127140

128-
assert_cppcheck(args, ec_exp=0, err_exp=[], out_exp=out_lines)
141+
exitcode, stdout, stderr = cppcheck(args)
142+
assert exitcode == 0, stdout
143+
assert stdout.splitlines() == out_lines
144+
assert __check_deprecation(stderr, test_file) == []
129145

130146

131147
def test_include(tmp_path):
@@ -151,7 +167,7 @@ def test_warning(tmpdir): # #12424
151167
exitcode, stdout, stderr = cppcheck(['-q', '--enable=warning', '--clang', test_file])
152168
assert exitcode == 0, stderr # do not assert
153169
assert stdout == ''
154-
assert stderr == ''
170+
assert __check_deprecation(stderr, test_file) == []
155171

156172

157173
def __test_cmd(tmp_path, file_name, extra_args, stdout_exp_1, content=''):
@@ -173,7 +189,7 @@ def __test_cmd(tmp_path, file_name, extra_args, stdout_exp_1, content=''):
173189

174190
exitcode, stdout, stderr = cppcheck(args, cwd=tmp_path)
175191
assert exitcode == 0, stderr if not stdout else stdout
176-
assert stderr == ''
192+
assert __check_deprecation(stderr, file_name) == []
177193
assert stdout.splitlines() == [
178194
'Checking {} ...'.format(file_name),
179195
'clang -fsyntax-only -Xclang -ast-dump -fno-color-diagnostics {}{}'.format(stdout_exp_1, file_name)
@@ -279,7 +295,7 @@ def test_debug_clang_output(tmp_path):
279295

280296
exitcode, stdout, stderr = cppcheck(args)
281297
assert exitcode == 0, stderr if not stdout else stdout
282-
assert stderr == ''
298+
assert __check_deprecation(stderr, test_file) == []
283299
assert stdout.startswith('TranslationUnitDecl'), stdout
284300
assert stdout.find(str(test_file)) != -1, stdout
285301

@@ -312,7 +328,7 @@ def test_debug_clang_output_failure_exitcode(tmp_path):
312328

313329
exitcode, stdout, stderr = cppcheck(args)
314330
assert exitcode == 0, stderr if not stdout else stdout
315-
stderr_lines = stderr.splitlines()
331+
stderr_lines = __check_deprecation(stderr, test_file)
316332
assert len(stderr_lines) > 5, stderr_lines
317333
assert (stderr_lines[0] ==
318334
"Failed to execute 'clang -fsyntax-only -Xclang -ast-dump -fno-color-diagnostics -x c {} 2>&1' - (exitcode: 1 / output: {}:3:12: error: indirection requires pointer operand ('int' invalid)".format(test_file, test_file))

0 commit comments

Comments
 (0)