Skip to content

with migrate lowers a GNU statement expression used as a value: its statements, then its last expression (#955) - #3569

Merged
ehartford merged 2 commits into
mainfrom
migrate-stmt-expr-value
Nov 23, 2026
Merged

ehartford merged 2 commits into
mainfrom
migrate-stmt-expr-value

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

Part of #955. Does not close it.

with migrate lowered a GNU statement expression only where its value was discarded (and one <math.h> comparison form). As a value it was refused: unsupported assignment rhs in goto CFG (kind=121), or a bail at the declaration inside it.

Now x = ({ T t = …; t * 2; }) is its statements, in order, followed by its last expression as the value:

  • as an initializer, on the right of an assignment (in a function lowered with gotos too), and as an operand;
  • a declaration inside extends the scope the later statements and the value are lowered in, as a compound statement's does;
  • the statements join the enclosing body, where the migrator already renames a local apart from another of its name (__local_t, __local_t_1), so two statement expressions declaring one name do not collide;
  • each is evaluated once, in order.

No new mechanism: it uses the setup-plus-value form the conditional and ?: lowerings already return.

Test. bs_check_migrate_statement_expression_values (basic migrator lane): a C program whose main returns the number of the first wrong result, covering the three positions, same-named locals, a goto-lowered function building a record through one, and evaluation count and order. The migrated program returns 0 as C does.

Roundtrip after this. The function this was found in (Compilation.bundle_contract_rows) now stops one step later, at __builtin_alloca, which the C backend uses on purpose for a closure created in a loop. With has no stack-allocation primitive, so that is a language question and is recorded on #955, not worked around here.

:c-migrator-tests green. Battery green (926 s); self-audit and :release-checks green (590 s).

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