Skip to content

Fix #15259 (isAliasOf: alias values are filtered again for every AST node in the expression) - #9062

Open
danmar wants to merge 1 commit into
cppcheck-opensource:mainfrom
cppchecksolutions:fix-15259
Open

danmar wants to merge 1 commit into
cppcheck-opensource:mainfrom
cppchecksolutions:fix-15259

Conversation

@danmar

@danmar danmar commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

The values of the reference token were filtered again for every node in the expression. Filter them once and skip the AST search when there is nothing that can match.

No changed warnings in a 50 package debian corpus, ValueFlow ~10% faster.

…node in the expression)

The values of the reference token were filtered again for every node
in the expression. Filter them once and skip the AST search when there
is nothing that can match.

No changed warnings in a 50 package debian corpus, ValueFlow ~10% faster.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@danmar danmar added the ai-assisted contains code which was written with the assistance of AI - please review extra carefully label Nov 23, 2026

@dmcppcheck dmcppcheck left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI review

I found no problems. The refactored isAliasOf() behaves the same as before: the deref condition and the filtered alias values are now computed once per reference instead of for every AST node, and the early continue only skips searches that could never match. The new expr && guard is needed, and the regression test that was added catches the case where it is missing (see testing). There are no earlier comments to track.

Testing

  • I built cppcheck and testrunner in both pr/ and base/, and both builds succeeded.
  • ./testrunner TestValueFlow passes in the PR. The full ./testrunner -q also passes, with 0 failures.
  • New test in base: I copied the PR's testvalueflow.cpp into base, and it passes there too. Base never crashed on this code, because findAstNode(nullptr, …) returns nothing.
  • New test without the guard: I removed the expr && guard from the hoisted deref in a copy of the PR. With that change, TestValueFlow::valueFlowCrash crashes. So the test does protect the new guard.
  • Differential run: I ran base and PR cppcheck --enable=all --inconclusive --check-level=exhaustive on every file in test/cfg/*.c* and samples/*/*. The outputs were identical (2451 lines each).
  • Alias cases: I wrote small cases in scratch/a.cpp (pointer to a local, array alias, reference to a struct, pointer parameter alias, pointer to a reference) and ran them with --debug-warnings. Base and PR gave identical output.
  • I did not measure the performance gain.

Automated review of 9d1c87a by Claude. The pull request was built and tested locally.

@dmcppcheck

Copy link
Copy Markdown
Contributor

Test results for commit 9d1c87a (tools/test-my-pr.py, main compared to this PR):

Test: http://ec2-16-170-140-253.eu-north-1.compute.amazonaws.com/pr-9062/
packages: 100
Differing warnings: 0 (+0 -0)
Timing: -7.6% (http://ec2-16-170-140-253.eu-north-1.compute.amazonaws.com/pr-9062/2026-11-23_19-28-45-9d1c87a636a0_timing.html)

Posted automatically by the cppcheck PR test runner. +N: warnings only with this PR, -N: warnings only with main. The AI review is written by Claude and can be wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-assisted contains code which was written with the assistance of AI - please review extra carefully

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants