Skip to content

Translated C: a static local is one object; an extern local names the file-scope variable - #3244

Merged
ehartford merged 1 commit into
laws-cleanupfrom
static-local
Nov 11, 2026
Merged

ehartford merged 1 commit into
laws-cleanupfrom
static-local

Conversation

@ehartford

@ehartford ehartford commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

A local declared static (C11 6.2.4p3) was translated as an ordinary local by c_import and with migrate: next_id() returned 1, 1, 1. It is now a module-level __static_<function>_<name> declared beside its function with its constant initializer; two blocks declaring the same name get two objects; _Thread_local carries over.

extern int shared; in a body (6.2.2p4) was a fresh local too. It now names the file-scope variable; one with no file-scope declaration, or shadowed by a local in scope, is refused by name.

Evidence: test/behavior/behav_c_import_static_local_keeps_its_value.w printed 1 1 1 / 0 0 0 / 5 6 / 11 11 21 21 / 0 4 under the installed compiler.

No corpus is re-promoted (D112).

Battery: GREEN on 1a170fc (out/battery/battery.log: rc=0 green; uat 12 pass, 1 skip by platforms:).

… local names the file-scope variable

A local declared `static` (C11 6.2.4p3) was translated as an ordinary
local, by c_import and by with migrate: every call started from the
initializer again (next_id() returned 1, 1, 1). It is now a module-level
variable declared beside its function as __static_<function>_<name>, with
its constant initializer; two blocks that each declare the name get two
objects; _Thread_local carries over.

`extern int shared;` in a body (6.2.2p4) was a fresh local too, so the
function wrote a copy nobody read. It now declares nothing and the name is
the file-scope variable's; one with no file-scope declaration, or one that
would be shadowed by a local in scope, is refused by name.

Evidence: test/behavior/behav_c_import_static_local_keeps_its_value.w
printed "1 1 1 / 0 0 0 / 5 6 / 11 11 21 21 / 0 4" under the installed
compiler.
@ehartford
ehartford added this pull request to stack #3245 November 11, 2026 03:05
@ehartford ehartford changed the title static local Translated C: a static local is one object; an extern local names the file-scope variable Nov 11, 2026
@ehartford
ehartford marked this pull request as ready for review November 11, 2026 03:05
@ehartford
ehartford merged commit 2915d11 into main Nov 11, 2026
@ehartford
ehartford deleted the static-local branch November 11, 2026 03:06
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