Skip to content

Conversation

@MathiasVP
Copy link
Contributor

Both sizeof(myType) and sizeof(myExpr) exists in C/C++, and we currently have a class for each case (SizeofTypeOperator and SizeofExprOperator, respectively) with a common superclass SizeofOperator.

This PR lifts the getTypeOperand member predicate from SizeofTypeOperator to the superclass with the intuitive implementation that, in the case of sizeof(myExpr) it should return the type of myExpr. This makes the superclass much more useful.

:til: there's also a __datasizeof in Clang so I made a similar transformation on that one.

Copilot AI review requested due to automatic review settings November 18, 2025 19:57
@MathiasVP MathiasVP requested a review from a team as a code owner November 18, 2025 19:57
@github-actions github-actions bot added the C++ label Nov 18, 2025
@MathiasVP MathiasVP added the no-change-note-required This PR does not need a change note label Nov 18, 2025
Copilot finished reviewing on behalf of MathiasVP November 18, 2025 19:59
Copy link
Contributor

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 lifts the getTypeOperand() method from the SizeofTypeOperator subclass to the SizeofOperator superclass, making it available for both type and expression operands. For sizeof(myExpr), the method now returns the type of the expression. The same transformation is applied to the DatasizeofOperator hierarchy.

Key Changes:

  • Added getTypeOperand() to SizeofOperator and DatasizeofOperator base classes with default implementation { none() }
  • Implemented overrides in expression operator subclasses to return the type of the contained expression
  • Updated test to call the method on the superclass, demonstrating it now works for all sizeof variants

Reviewed Changes

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

File Description
cpp/ql/lib/semmle/code/cpp/exprs/Cast.qll Added getTypeOperand() to superclasses SizeofOperator and DatasizeofOperator, with appropriate overrides in subclasses
cpp/ql/test/library-tests/types/sizeof/sizeof.ql Updated test to call getTypeOperand() on SizeofOperator instead of SizeofTypeOperator
cpp/ql/test/library-tests/types/sizeof/sizeof.expected Updated expected results to include type operands for expression-based sizeof operations

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@jketema
Copy link
Contributor

jketema commented Nov 18, 2025

:til: there's also a __datasizeof in Clang so I made a similar transformation on that one.

That's a pretty recent addition actually.

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 if CI and DCA are happy.

@MathiasVP
Copy link
Contributor Author

DCA was uneventful. Merging!

@MathiasVP MathiasVP merged commit 73e72f5 into github:main Nov 18, 2025
16 checks passed
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.

2 participants