Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

C++: Fix IR edge case where there are no function calls taking an argument #19493

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 2 commits into from
May 15, 2025

Conversation

jketema
Copy link
Contributor

@jketema jketema commented May 14, 2025

No description provided.

@github-actions github-actions bot added the C++ label May 14, 2025
@jketema jketema marked this pull request as ready for review May 14, 2025 12:15
@Copilot Copilot AI review requested due to automatic review settings May 14, 2025 12:15
@jketema jketema requested a review from a team as a code owner May 14, 2025 12:15
@jketema jketema requested a review from MathiasVP May 14, 2025 12:15
@jketema jketema added the no-change-note-required This PR does not need a change note label May 14, 2025
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

Adds handling for an IR edge case where no function calls take arguments but a delete expression is present; includes tests and updates the printing logic to accommodate delete expressions.

  • Introduces a new test (test.cpp) covering a function with only a delete expression and a call without args.
  • Adds configurations and expected outputs for both IR and AST printing.
  • Extends hasPositionalArgIndex in IRCppLanguage.qll to treat delete expressions as taking a single argument.

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
cpp/ql/test/library-tests/ir/no-function-calls/test.cpp New C++ test for function with only delete and no-arg calls
cpp/ql/test/library-tests/ir/no-function-calls/aliased_ir.ql IR graph import and custom PrintConfig for aliased IR output
cpp/ql/test/library-tests/ir/no-function-calls/aliased_ir.expected Expected IR output for the new test
cpp/ql/test/library-tests/ir/no-function-calls/PrintConfig.qll Predicates for filtering declarations based on source location
cpp/ql/test/library-tests/ir/no-function-calls/PrintAST.ql AST graph import and custom PrintConfig for AST output
cpp/ql/test/library-tests/ir/no-function-calls/PrintAST.expected Expected AST output for the new test
cpp/ql/lib/semmle/code/cpp/ir/internal/IRCppLanguage.qll Extended hasPositionalArgIndex to include delete expressions
Comments suppressed due to low confidence (1)

cpp/ql/test/library-tests/ir/no-function-calls/PrintAST.ql:9

  • [nitpick] This class name duplicates the IR printing configuration. Rename to PrintAstConfig (or similar) to avoid confusion between IR and AST configurations.
private class PrintConfig extends PrintAstConfiguration {

Comment on lines +75 to +76
exists(Cpp::DeleteExpr d) and
argIndex = 0
Copy link
Preview

Copilot AI May 14, 2025

Choose a reason for hiding this comment

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

The clause makes hasPositionalArgIndex(0) true for any delete expression in the module rather than when the delete’s argument is at the target index. Consider scoping this to the specific delete node, e.g., exists(Cpp::DeleteExpr d | exists(d.getChild(argIndex))) to ensure correctness.

Suggested change
exists(Cpp::DeleteExpr d) and
argIndex = 0
exists(Cpp::DeleteExpr d | exists(d.getChild(argIndex)))

Copilot uses AI. Check for mistakes.

Positive FeedbackNegative Feedback
Copy link
Contributor

@MathiasVP MathiasVP left a comment

Choose a reason for hiding this comment

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

Changes LGTM if DCA is happy. I'll let someone from the C team formally approve it 🙂

Copy link
Contributor

@tausbn tausbn left a comment

Choose a reason for hiding this comment

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

I am by no means an expert in this stuff, but the tests and changes look good to me. My only question is whether there are other parts that (like delete) are represented as function calls, and that should therefore also be added to hasPositionalArgIndex.

@jketema
Copy link
Contributor Author

jketema commented May 15, 2025

My only question is whether there are other parts that (like delete) are represented as function calls, and that should therefore also be added to hasPositionalArgIndex.

That's a good question. I don't think there are any other cases where we're synthesizing a function call with at least one argument, while there's no actual call in the database. What do you think @MathiasVP?

@MathiasVP
Copy link
Contributor

That's a good question. I don't think there are any other cases where we're synthesizing a function call with at least one argument, while there's no actual call in the database. What do you think @MathiasVP?

I'm not aware of any such cases, no. I'm also fairly sure the answer is 'no' based on the following rather ad-hoc investigation:

  1. I searched for Opcode::Call in our repo (which is how we generate CallInstructions. This gave me 1 hit: The one in the TranslatedCall abstract class.
  2. I then searched for any class that (transitively) extend TranslatedCall. This gives all the obvious subclasses in TranslatedCall (which works directly on Calls), and the TranslatedDeleteOrDeleteArrayExpr case that we're fixing in this PR.

So since 2. gave me no other results I'm pretty sure the answer is no 🤞

@jketema jketema merged commit 51229a6 into github:main May 15, 2025
17 of 18 checks passed
@jketema jketema deleted the delete-expr branch May 15, 2025 11:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C++ no-change-note-required This PR does not need a change note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.