Skip to content

C++: Fix typeid IR translation #20060

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 4 commits into from
Jul 16, 2025
Merged

C++: Fix typeid IR translation #20060

merged 4 commits into from
Jul 16, 2025

Conversation

jketema
Copy link
Contributor

@jketema jketema commented Jul 15, 2025

No description provided.

@Copilot Copilot AI review requested due to automatic review settings July 15, 2025 18:20
@jketema jketema requested a review from a team as a code owner July 15, 2025 18:20
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 fixes the IR translation for C++ typeid expressions by implementing proper IR instructions for both typeid with expressions and typeid with types. The changes address consistency issues in the IR generation where typeid operations were previously not properly handled.

Key changes:

  • Adds new IR instruction types TypeidExpr and TypeidType with corresponding opcodes
  • Implements TranslatedTypeidExpr class to handle the translation of typeid operations
  • Updates test expectations to reflect the corrected IR generation

Reviewed Changes

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

File Description
cpp/ql/lib/semmle/code/cpp/ir/implementation/Opcode.qll Adds TTypeidExpr and TTypeidType opcodes with their corresponding classes
cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/Instruction.qll Defines TypeidExprInstruction and TypeidTypeInstruction classes
cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/TranslatedExpr.qll Implements TranslatedTypeidExpr class for handling typeid expression translation
Multiple .expected files Updates test expectations to reflect the fixed IR translation

@github-actions github-actions bot added the C++ label Jul 15, 2025
@jketema jketema added the no-change-note-required This PR does not need a change note label Jul 15, 2025
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.

One comment, but otherwise this LGTM if DCA comes back happy!

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.

Final rounds of comments and then I think we're there 🥳

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.

LGTM (once DCA comes back happy)!

@jketema
Copy link
Contributor Author

jketema commented Jul 16, 2025

It looks likes this gives a slowdown on zeek/spicy. It looks like that project uses typeid in some of it's general error handling routines, so I suspect we get a lot more flow through those now. It's difficult to exactly tell from the DCA data though.

The other projects in DCA look fine.

@MathiasVP
Copy link
Contributor

MathiasVP commented Jul 16, 2025

Makes sense. I think that's fine. I'm quite happy with the large reduction in instructionWithoutSuccessor 🥳

Did you see that there's a large increase in missingOperandType consistency errors for drogon?

@jketema
Copy link
Contributor Author

jketema commented Jul 16, 2025

Did you see that there's a large increase in missingOperandType consistency errors for drogon?

Yes, drogon also has some uses of typeid (including some in templates), so I assume it has to do with that. Not sure if I should investigate here.

@MathiasVP
Copy link
Contributor

Yeah, I don't think this needs to be looked at in this PR since I highly doubt that this PR does anything incorrectly.

@jketema
Copy link
Contributor Author

jketema commented Jul 16, 2025

Ok, merging.

@jketema jketema merged commit 200d46f into github:main Jul 16, 2025
15 checks passed
@jketema jketema deleted the typeid-fix branch July 16, 2025 10:40
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