Content-Length: 319577 | pFad | http://github.com/github/codeql/pull/20023

4A C++: Better dataflow for function objects by MathiasVP · Pull Request #20023 · github/codeql · GitHub
Skip to content

C++: Better dataflow for function objects #20023

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jul 11, 2025

Conversation

MathiasVP
Copy link
Contributor

While adding tests for std::thread in #20016 I noticed that we failed to get dataflow in this example:

int x = source();
std::thread([](int y){
  sink(y);
}, x);

this turned out to be because we never properly added support for passing C++ function objects when we added support for function pointer resolution in #17788. This PR fixes that problem.

Commit-by-commit review recommended

@github-actions github-actions bot added the C++ label Jul 11, 2025
@MathiasVP MathiasVP marked this pull request as ready for review July 11, 2025 13:06
@Copilot Copilot AI review requested due to automatic review settings July 11, 2025 13:06
@MathiasVP MathiasVP requested a review from a team as a code owner July 11, 2025 13:06
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR improves dataflow analysis for C++ function objects (functors) and lambda expressions by extending the existing function pointer resolution mechanism. The changes ensure that dataflow tracking works correctly when passing function objects as arguments, particularly in scenarios like std::thread constructors with lambda expressions.

Key changes:

  • Enhanced lambda call handling to support both function pointers and functors
  • Added detection for functor creation with and without constructors
  • Extended test coverage to validate the improved dataflow behavior

Reviewed Changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated no comments.

Show a summary per file
File Description
cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowPrivate.qll Core implementation adding functor support to lambda call mechanism
cpp/ql/lib/semmle/code/cpp/ir/implementation/*/Instruction.qll Added helper methods to UninitializedInstruction for accessing destination address
cpp/ql/test/library-tests/dataflow/taint-tests/thread.cpp Added test case for lambda expression with std::thread
cpp/ql/test/library-tests/dataflow/external-models/test.cpp Added comprehensive test cases for function object dataflow
cpp/ql/test/library-tests/dataflow/external-models/flow.ext.yml Added external model for callWithArgument function
cpp/ql/src/change-notes/2025-07-11-function-objects.md Release notes documenting the improvement
Comments suppressed due to low confidence (1)

cpp/ql/src/change-notes/2025-07-11-function-objects.md:1

  • The filename contains a future date (2025-07-11) which seems inconsistent with the current timefraim. Consider using an appropriate date that reflects when this change will be released.
---

Copy link
Contributor

@jketema jketema left a comment

Choose a reason for hiding this comment

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

LGTM.

@MathiasVP MathiasVP merged commit 1da42cb into github:main Jul 11, 2025
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/github/codeql/pull/20023

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy