Skip to content

Preserve GNU statement expressions in folded logical operands. [GH #573] - #574

Open
jakub-labenski wants to merge 1 commit into
edgcpp:mainfrom
jakub-labenski:fix/short-circuit-statement-expr
Open

jakub-labenski wants to merge 1 commit into
edgcpp:mainfrom
jakub-labenski:fix/short-circuit-statement-expr

Conversation

@jakub-labenski

@jakub-labenski jakub-labenski commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

The C++-generating back end could fail with check_for_and_take_source_seq_entry: wrong entry when the right operand of a short-circuited && or || contained a GNU statement expression. Constant folding removed the operand’s source-sequence entries even when it retained the operand in a backing expression for C++ generation.

Preserve those entries whenever the backing expression is retained. Add regression coverage for both operators in Clang and GCC emulation, including nested expressions with a local type declaration.

Discussion #573.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed a crash during C++ generation when a skipped right-hand operand of a short-circuit expression contains a statement expression with a local declaration.
    • Improved handling of constant && and || expressions while preserving required behavior when expression results are recorded.
  • Tests
    • Added regression coverage for built-in logical operators, including nested expressions, skipped operands, and cases involving overloaded operator declarations.

@jakub-labenski
jakub-labenski requested a review from a team November 20, 2026 13:28
@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The logical-operator folding branch now handles constant-left && and || cases together. It conditionally retains statement-expression references when a backing expression is recorded. New regression coverage tests statement-expression operands, nested expressions, and compiler modes.

Changes: Short-circuit folding

Layer / File(s) Summary
Fold logical operators
src/exprutil.c, src/pending_changes/gh-577-short-circuit-statement-expr.txt
The folding branch handles both && and `
Cover statement-expression cases
tests/tests/regressions/gh-577-short-circuit-statement-expr.sft.cpp, tests/tests/regressions/.gh-577-short-circuit-statement-expr.rto/*
The regression test covers built-in short-circuit expressions with statement-expression operands, nested cases, local declarations, and overloaded operator declarations. The fixtures select Clang and GNU compiler modes.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Possibly related issues

Suggested labels: bug

Suggested reviewers: daveedvdv, daveedvdv-nvidia

Merge Risk: Minimal · up to 842f2

This change fixes an assertion failure in the C++-generating back end for statement expressions in short-circuited logical operands. It adds regression tests for both operators. No concrete merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: GNU statement expressions in the right operand of folded logical operands are kept. The raw summary and objectives both describe this change to short-circuit && and ||…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: GNU statement expressions in the right operand of folded logical operands are kept. The raw summary and objectives both describe this change to short-circuit && and || folding in src/exprutil.c, plus regression tests and a pending-change note. The title includes a ticket reference ([GH #573]) that does not match the PR number #574 in the objectives, but the title itself is accurate and specific, so the check passes.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 6967ccc and 842f281.

Files selected for processing: 5

  • src/exprutil.c
  • src/pending_changes/gh-577-short-circuit-statement-expr.txt
  • tests/tests/regressions/.gh-577-short-circuit-statement-expr.rto/default.1.1.txt
  • tests/tests/regressions/.gh-577-short-circuit-statement-expr.rto/default.2.1.txt
  • tests/tests/regressions/gh-577-short-circuit-statement-expr.sft.cpp
Files skipped from review as they are similar to previous changes: 1

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.

@jakub-labenski
jakub-labenski force-pushed the fix/short-circuit-statement-expr branch from 691a6cb to d84e8d0 Compare November 20, 2026 14:49
@edgcpp-bot

Copy link
Copy Markdown
Collaborator

AcknowlEDG review results updated for d84e8d04a452:

CI success.

@jakub-labenski

Copy link
Copy Markdown
Contributor Author

Issue: #577

@jakub-labenski
jakub-labenski force-pushed the fix/short-circuit-statement-expr branch from d84e8d0 to 6967ccc Compare November 20, 2026 18:42

@nv-cmeerw nv-cmeerw left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for working on this, just a few nits.

@@ -0,0 +1,9 @@
[GH #577]
C++-generating back end: GNU statement expressions in logical operands

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think I would highlight the abort: C++-generating back end: Abort on GNU statement expressions in logical operands

and then ... could abort with a failed assertion in check_for_and_take_source_seq_entry when ..., and maybe instead of the implementation internals just show an example: For example, with --gnu_version=150200:

struct S { bool operator&&(int); };
bool f(int n) {
  return false && ({ int i = n; i; });  // Previously triggered an abort.
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Changed as requested.

Comment thread src/exprutil.c Outdated
discard_operand(operand_2);
make_integer_constant_operand(result, (a_host_large_integer)0);
make_integer_constant_operand(result,
(a_host_large_integer)(op == eok_lor));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That indentation seems off by one

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Should be fixed now.

@jakub-labenski
jakub-labenski force-pushed the fix/short-circuit-statement-expr branch from 6967ccc to 842f281 Compare November 20, 2026 19:30
@edgcpp-bot

Copy link
Copy Markdown
Collaborator

AcknowlEDG review results updated for 842f28149b10:

@edgcpp-bot

Copy link
Copy Markdown
Collaborator

AcknowlEDG review results updated for 842f28149b10:

CI success.

@nv-cmeerw nv-cmeerw left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks, looks good to me now.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants