Skip to content

migrate: a discarded expression's failed lowering becomes an empty statement (lower_discard_expr_side_effects_ir tail); generated overflow helpers collide with C globals a/b/out #1933

Closed

Description

@ehartford

Found while fixing #1911 (branch fix-1911).

CiStmtPool.lower_discard_expr_side_effects_ir (src/CImport.w) still ends:

let lowered = self.lower_value_expr_ir(session, cursor, exprs, types, scope)
if ci_value_ir_valid(lowered) and (lowered.setup_stmt as i32) != 0:
    return lowered.setup_stmt
self.empty_stmt_ir()

A discarded expression ((void)e, the left of a comma) whose value lowering FAILS becomes an empty statement instead of failing the function (the statement contract is "zero means failure"). That is the silent drop class #1911 hit through the comma branch (glibc's assert ran on); fix-1911 closed the comma, __extension__, statement-expression and unary/binary-operand paths, and left this tail. I have not yet found a C expression that reaches it with a failed lowering — a repro is the first step; then return 0 there.

(Separately noticed: migrating int f(void); int a[4]; void t(void) { (void) a[f()]; } emits a global a that collides with the a parameter of every generated __with_builtin_*_overflow_* helper — "shadowing is not allowed for 'a'" — so any C file with a global named a, b or out fails to compile after migration. (void) a[f()] itself is kept as a[unsafe { f() }].)

Activity

  1. changed the title [-]migrate: a discarded expression's failed lowering or nested side effects vanish (lower_discard_expr_side_effects_ir tail)[/-] [+]migrate: a discarded expression's failed lowering becomes an empty statement (lower_discard_expr_side_effects_ir tail); generated overflow helpers collide with C globals a/b/out[/+] on Sep 30, 2026
  2. ehartford commented on Oct 3, 2026

    @ehartford
    ContributorAuthor

    Fixed on main by bfa0201 (#1934): the discard tail of lower_discard_expr_side_effects_ir now lowers through lower_effect_expr_ir, so a failed discarded lowering fails the statement; the overflow helpers' locals are __with_-prefixed. Verified on stage1 of main 9307016: int a[4]; (void) a[f()]; migrates and checks with no shadowing error; (void)(c ? a[g()] : 0) keeps the call inside an if/else. Fixtures behav_migrate_discarded_effects.w, behav_migrate_helper_hygiene.w.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions