Skip to content

Commit 719ee61

Browse files
authored
fixed #13376 - include --check-level in analyzer information hash (#7072)
1 parent 72c775a commit 719ee61

2 files changed

Lines changed: 49 additions & 0 deletions

File tree

lib/cppcheck.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,8 @@ static std::size_t calculateHash(const Preprocessor& preprocessor, const simplec
649649
toolinfo << (settings.severity.isEnabled(Severity::portability) ? 'p' : ' ');
650650
toolinfo << (settings.severity.isEnabled(Severity::information) ? 'i' : ' ');
651651
toolinfo << settings.userDefines;
652+
toolinfo << std::to_string(static_cast<std::uint8_t>(settings.checkLevel));
653+
// TODO: do we need to add more options?
652654
settings.supprs.nomsg.dump(toolinfo);
653655
return preprocessor.calculateHash(tokens, toolinfo.str());
654656
}

test/cli/other_test.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import json
88

99
from testutils import cppcheck, assert_cppcheck, cppcheck_ex
10+
from xml.etree import ElementTree
1011

1112

1213
def __remove_std_lookup_log(l : list, exepath):
@@ -2269,3 +2270,49 @@ def test_dumpfile_platform(tmpdir):
22692270
break
22702271
assert ' wchar_t_bit="' in platform
22712272
assert ' size_t_bit="' in platform
2273+
2274+
2275+
def test_builddir_hash_check_level(tmp_path): # #13376
2276+
test_file = tmp_path / 'test.c'
2277+
with open(test_file, 'wt') as f:
2278+
f.write("""
2279+
void f(bool b)
2280+
{
2281+
for (int i = 0; i < 2; ++i)
2282+
{
2283+
if (i == 0) {}
2284+
if (b) continue;
2285+
}
2286+
}
2287+
""")
2288+
2289+
build_dir = tmp_path / 'b1'
2290+
os.mkdir(build_dir)
2291+
2292+
args = [
2293+
'--enable=warning', # to execute the code which generates the normalCheckLevelMaxBranches message
2294+
'--enable=information', # to show the normalCheckLevelMaxBranches message
2295+
'--cppcheck-build-dir={}'.format(build_dir),
2296+
'--template=simple',
2297+
str(test_file)
2298+
]
2299+
2300+
exitcode, stdout, stderr = cppcheck(args)
2301+
assert exitcode == 0, stdout
2302+
assert stderr == '{}:0:0: information: Limiting analysis of branches. Use --check-level=exhaustive to analyze all branches. [normalCheckLevelMaxBranches]\n'.format(test_file)
2303+
2304+
cache_file = (build_dir / 'test.a1')
2305+
2306+
root = ElementTree.fromstring(cache_file.read_text())
2307+
hash_1 = root.get('hash')
2308+
2309+
args += ['--check-level=exhaustive']
2310+
2311+
exitcode, stdout, stderr = cppcheck(args)
2312+
assert exitcode == 0, stdout
2313+
assert stderr == ''
2314+
2315+
root = ElementTree.fromstring(cache_file.read_text())
2316+
hash_2 = root.get('hash')
2317+
2318+
assert hash_1 != hash_2

0 commit comments

Comments
 (0)