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 an issue where compile-time evaluation of && and || could lose required references to declarations inside GNU statement expressions.
  • Tests
    • Added regression coverage for short-circuit expressions, including nested expressions and local 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 constant-folding branch now handles determining cases for both && and ||. It conditionally preserves statement-expression references. Regression cases cover built-in short-circuit operators and statement expressions with local declarations.

Changes: Short-circuit folding

Layer / File(s) Summary
Fold logical operators
src/exprutil.c, src/pending_changes/gh-573-short-circuit-statement-expr.txt
The branch handles constant-left && false and `
Cover statement-expression cases
tests/tests/regressions/short-circuit-statement-expr.sft.cpp, tests/tests/regressions/.short-circuit-statement-expr.rto/*
Regression cases cover built-in and overloaded logical operators, nested cases, and local declarations in statement expressions. Test configurations invoke Clang and GNU compiler modes.

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

Change: Bug fix · Severity of issue fixed: Medium

Suggested labels: bug

Suggested reviewers: daveedvdv, daveedvdv-nvidia

Merge Risk: Minimal · up to d84e8

The change preserves source-sequence entries when a short-circuited operand containing a GNU statement expression is retained for C++ generation. No concrete merge-blocking risk was found, and the regression cases cover both operators in Clang and GNU modes.

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 states the main change: GNU statement expressions in folded logical operands are now preserved. The raw summary and PR objectives confirm the fix for the `check_for_and_take_source_seq_entry…
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 states the main change: GNU statement expressions in folded logical operands are now preserved. The raw summary and PR objectives confirm the fix for the check_for_and_take_source_seq_entry: wrong entry crash in the C++ back end, which keeps source-sequence entries when a short-circuited && or || operand is retained as a backing expression. The title is specific, concise, and includes the issue reference.

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 691a6cb and d84e8d0.

Files selected for processing: 5

  • src/exprutil.c
  • src/pending_changes/gh-573-short-circuit-statement-expr.txt
  • tests/tests/regressions/.short-circuit-statement-expr.rto/default.1.1.txt
  • tests/tests/regressions/.short-circuit-statement-expr.rto/default.2.1.txt
  • tests/tests/regressions/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; 3 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

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.

1 participant