C++: Better dataflow for function objects#20023
Merged
MathiasVP merged 8 commits intogithub:mainfrom Jul 11, 2025
Merged
Conversation
Contributor
There was a problem hiding this comment.
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 timeframe. Consider using an appropriate date that reflects when this change will be released.
---
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
While adding tests for
std::threadin #20016 I noticed that we failed to get dataflow in this example: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