Menu ▾ ▴

2.22.0 regression: --cppcheck-build-dir cache misses on 2nd run when include load order differs from alphabetical order

Jaeyoun Yi
7 days ago
4 days ago
  • Jaeyoun Yi

    Jaeyoun Yi - 7 days ago

    Since 2.22.0 the --cppcheck-build-dir cache is discarded with "hash mismatch" on the first re-run of an unchanged file, and only hits from the 3rd run on. 2.21.1 hits on the 2nd run.

    In our project almost every TU includes {fmt} 12 (base.h -> format.h -> format-inl.h), so the first re-scan after a full scan re-analyzes everything.

    Minimal reproduction (no options other than the build dir):

    mkdir repro && cd repro && mkdir bd
    printf '#include "z.h"\n' > t.cpp
    printf '#include "a.h"\n' > z.h
    printf 'int a;\n' > a.h
    for i in 1 2 3; do cppcheck --cppcheck-build-dir=bd --debug-analyzerinfo t.cpp 2>&1 | grep -E "cached|skipping"; done
    

    2.22.0 output:

    no cached result 'bd/t.a1' for 't.cpp' found
    discarding cached result from 'bd/t.a1' for 't.cpp' - hash mismatch
    skipping analysis - loaded 0 cached finding(s) from 'bd/t.a1' for 't.cpp'
    

    2.21.1 output:

    no cached result 'bd/t.a1' for 't.cpp' found
    skipping analysis - loaded 0 cached finding(s) from 'bd/t.a1' for 't.cpp'
    skipping analysis - loaded 0 cached finding(s) from 'bd/t.a1' for 't.cpp'
    

    If the include chain is t.cpp -> a.h -> z.h (load order == alphabetical order), 2.22.0 hits on the 2nd run as expected.

    Likely cause: in 2.22.0 the stored <hash> is calculated after preprocessing (files loaded in include order), while the lookup hash is calculated after pre-loading the files listed in <includes> of the existing .a1, which are written in sorted order. The hash seems to depend on the order in which files were loaded, so the two values differ until the .a1 written by the 2nd run is reused.

    Environment: Linux x86_64, cppcheck 2.22.0 built from source with gcc. Same result with --project=compile_commands.json and -j N.

    Could someone create a Trac ticket for this? Thanks.

     
  • Daniel Marjamäki

    Claude claims it is fixed:

    Yes, I reproduced it. The bug is real in 2.22.0 and already fixed on main by 7828b1be8 (Fix #15132, PR #8957, 2026-10-23).

    Feel free to test out HEAD.

     

    Last edit: Daniel Marjamäki 4 days ago

Log in to post a comment.