Repository navigation
Translated C: a static local is one object; an extern local names the file-scope variable - #3244
Merged
Merged
Conversation
… 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
marked this pull request as ready for review
November 11, 2026 03:05
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A local declared
static(C11 6.2.4p3) was translated as an ordinary local byc_importandwith 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_localcarries 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.wprinted1 1 1 / 0 0 0 / 5 6 / 11 11 21 21 / 0 4under 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 byplatforms:).