Skip to content

Conversation

@camc314
Copy link
Contributor

@camc314 camc314 commented Oct 20, 2025

When a switch case test contains a logical expression (|| or &&), visiting the expression creates multiple CFG blocks for short-circuit evaluation and changes current_node_ix. The condition instruction must be appended to the block BEFORE visiting the expression, not after.

This matches the pattern used in visit_if_statement and ensures the condition instruction is placed in the case entry block, making it discoverable by code that identifies case test blocks.

Before:

self.visit_expression(expr);  // moves current_node_ix
cfg.append_condition_to(cfg.current_node_ix, ...);  // wrong block

After:

let condition_block_ix = cfg.current_node_ix;  // save before
self.visit_expression(expr);
cfg.append_condition_to(condition_block_ix, ...);  // correct block

@github-actions github-actions bot added A-semantic Area - Semantic C-bug Category - Bug labels Oct 20, 2025
Copy link
Contributor Author

camc314 commented Oct 20, 2025


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@codspeed-hq
Copy link

codspeed-hq bot commented Oct 20, 2025

CodSpeed Performance Report

Merging #14810 will not alter performance

Comparing c/10-20-fix_cfg_append_switch_case_condition_to_correct_block (7e888d2) with main (aec04f2)

Summary

✅ 37 untouched

@camc314 camc314 marked this pull request as ready for review October 20, 2025 11:40
@camc314 camc314 requested a review from Dunqing as a code owner October 20, 2025 11:40
@camc314 camc314 self-assigned this Oct 20, 2025
@graphite-app graphite-app bot changed the base branch from c/10-20-fix_semantic_cfg_update_example_docs_code to graphite-base/14810 October 20, 2025 11:43
@graphite-app
Copy link
Contributor

graphite-app bot commented Oct 20, 2025

Merge activity

@graphite-app graphite-app bot changed the base branch from graphite-base/14810 to main October 20, 2025 11:49
When a switch case test contains a logical expression (|| or &&), visiting the expression creates multiple CFG blocks for short-circuit evaluation and changes current_node_ix. The condition instruction must be appended to the block BEFORE visiting the expression, not after.

This matches the pattern used in visit_if_statement and ensures the condition instruction is placed in the case entry block, making it discoverable by code that identifies case test blocks.

Before:
```rust
self.visit_expression(expr);  // moves current_node_ix
cfg.append_condition_to(cfg.current_node_ix, ...);  // wrong block

After:

let condition_block_ix = cfg.current_node_ix;  // save before
self.visit_expression(expr);
cfg.append_condition_to(condition_block_ix, ...);  // correct block
@graphite-app graphite-app bot force-pushed the c/10-20-fix_cfg_append_switch_case_condition_to_correct_block branch from fa8658e to 7e888d2 Compare October 20, 2025 11:50
@graphite-app graphite-app bot merged commit 7e888d2 into main Oct 20, 2025
29 checks passed
@graphite-app graphite-app bot deleted the c/10-20-fix_cfg_append_switch_case_condition_to_correct_block branch October 20, 2025 11:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-semantic Area - Semantic C-bug Category - Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants