Skip to content

with migrate: an extern global the unit only declares is raw: its read and write print inside unsafe, and an extern array of unknown size is indexed as a pointer (#3344) - #3353

Merged
ehartford merged 1 commit into
mainfrom
migrate-extern-unsafe
Nov 15, 2026

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

A file-scope variable the migrated unit only declares, and no unit of the migration defines, is emitted extern var / extern let. A body that names it reads or writes a C global: raw unless it is const or thread-local (§31.4), and an array of unknown size is declared as a pointer, so its index is a raw index. The bodies were emitted bare and the output did not check (E0921; "raw pointer indexing requires unsafe context").

extern int counter;               int bump(void) { counter = counter + 1; return counter; }
extern const unsigned char tab[]; int look(int i) { return tab[i]; }

now migrates to

unsafe { counter = ((counter + 1) as i32) }
return unsafe { counter }
return (((unsafe tab[__param_i]) as i32))

A const scalar extern and a global the unit defines are unchanged.

ci_migrate_collect_extern_vars (beside the collector for unsafe extern functions, with its std-zone exemption) names the variables per unit; the printer wraps a read (unsafe { name }), a statement-level write (the whole assignment), and the index of a pointer-declared extern, and prints them bare inside an unsafe fn.

Test: behav_3344_migrate_extern_global_is_raw (fails on the installed compiler, passes here; the migrated file must check).

Battery: GREEN. The run before it was red on unit-return-review (an explicit -> Unit on a new function; removed) and on pub-lint-check, whose analysis step timed out under machine load (by hand it reports nothing).

Still open on #3344: with migrate <dir> does not run the check the single-file form runs.

…nsafe when it is neither const nor thread-local, and an extern array of unknown size is indexed as the pointer it is declared as (#3344)
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