Skip to content

C++: Add support to __leave #19734

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 7 commits into from
Jun 13, 2025
Merged

C++: Add support to __leave #19734

merged 7 commits into from
Jun 13, 2025

Conversation

IdrissRio
Copy link
Contributor

@IdrissRio IdrissRio commented Jun 11, 2025

This PR adds support to the Microsoft-specific __leave statement.

@IdrissRio IdrissRio force-pushed the idrissrio/goto branch 3 times, most recently from b994559 to 04cb9e4 Compare June 12, 2025 12:33
@IdrissRio IdrissRio added the depends on internal PR This PR should only be merged in sync with an internal Semmle PR label Jun 12, 2025
@IdrissRio IdrissRio marked this pull request as ready for review June 13, 2025 07:04
@Copilot Copilot AI review requested due to automatic review settings June 13, 2025 07:04
@IdrissRio IdrissRio requested a review from a team as a code owner June 13, 2025 07:04
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 support for the Microsoft-specific __leave statement in the C++ QL libraries and tests.

  • Introduces a new LeaveStmt class and maps it to a fresh statement kind.
  • Updates the semmlecode schema, upgrade/downgrade scripts, and change notes.
  • Adds library tests (leave.cpp, leave.ql, leave.expected) to verify detection and enclosing-try resolution.

Reviewed Changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
cpp/ql/lib/semmlecode.cpp.dbscheme Add 40 = @stmt_leave and extend @jump to include @stmt_leave
cpp/ql/lib/semmle/code/cpp/stmts/Stmt.qll Define LeaveStmt class, implement getEnclosingTry recursive lookup
cpp/ql/lib/upgrades/3c45f8b9e71ec723bf50c40581e1f18f4f25e290/upgrade.properties Declare upgrade metadata for __leave support
cpp/ql/lib/change-notes/2025-06-11-leave-stmt.md Document feature addition of __leave statement
cpp/downgrades/a8c2176e9a5cf9be8d17053a4c8e7e56b5aced6d/upgrade.properties Declare downgrade metadata for __leave support
cpp/downgrades/a8c2176e9a5cf9be8d17053a4c8e7e56b5aced6d/stmts.ql Map legacy kinds, translating stmt_leave back to kind 4
cpp/ql/test/library-tests/stmt/leave/leave.ql Add QL test query selecting LeaveStmt and its enclosing try
cpp/ql/test/library-tests/stmt/leave/leave.expected Add expected results for leave.ql query
cpp/ql/test/library-tests/stmt/leave/leave.cpp Add C++ source with __leave in both __finally and __except contexts
Comments suppressed due to low confidence (1)

cpp/ql/lib/upgrades/3c45f8b9e71ec723bf50c40581e1f18f4f25e290/upgrade.properties:2

  • The upgrade properties do not include a stmts.rel: run stmts.qlo directive, so upgrade tests might not exercise the new __leave upgrade rules. Consider adding this to ensure the upgrade path is exercised.
compatibility: partial

}

private MicrosoftTryStmt getEnclosingTry(Stmt s) {
if s.getParent().getEnclosingStmt() instanceof MicrosoftTryStmt
Copy link
Preview

Copilot AI Jun 13, 2025

Choose a reason for hiding this comment

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

The recursive helper getEnclosingTry lacks a base case when no enclosing MicrosoftTryStmt exists, potentially leading to infinite recursion. Consider adding a guard that returns none() when reaching the root or a non-stmt parent.

Suggested change
if s.getParent().getEnclosingStmt() instanceof MicrosoftTryStmt
if s.getParent() = none() or s.getParent().getEnclosingStmt() = none()
then result = none()
else if s.getParent().getEnclosingStmt() instanceof MicrosoftTryStmt

Copilot uses AI. Check for mistakes.

@@ -2213,6 +2213,7 @@ case @stmt.kind of
| 37 = @stmt_co_return
| 38 = @stmt_consteval_if
| 39 = @stmt_not_consteval_if
| 40 = @stmt_leave
Copy link
Preview

Copilot AI Jun 13, 2025

Choose a reason for hiding this comment

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

[nitpick] The new stmt_leave enum entry is added out of numeric order among existing cases, which can make future maintenance harder. Consider inserting it in sorted order or updating surrounding comments.

Copilot uses AI. Check for mistakes.

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.

Two small comments, otherwise LGTM.

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

@IdrissRio IdrissRio merged commit 70647ce into main Jun 13, 2025
15 of 16 checks passed
@IdrissRio IdrissRio deleted the idrissrio/goto branch June 13, 2025 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C++ depends on internal PR This PR should only be merged in sync with an internal Semmle PR documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants