You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
A global initialized from another global reads garbage (heap-typed globals; crash with a class) #446
A module-level variable initialized from another module-level variable whose value lives on the heap (an array, a class instance) reads garbage. With a class instance the program dies with a breakpoint trap. This happens under every memory model, with or without the default library. Number globals are not affected.
leta: number[]=[1,2];letb=a;functionmain(){print(a.length,b.length);}
Under gc, rc and none, JIT fails with Exception Code: 0x80000003, and ahead-of-time compilation (test-runner) fails with exit code -2147483645 (also 0x80000003).
Control case: let a3 = 7; let b3 = a3; prints 7.
Likely cause
Each global gets its own initializer function, and both are listed in llvm.global_ctors with the same priority:
b's initializer region is just Load(AddressOf @a). LLVM leaves the order of equal-priority constructors unspecified. If b__cctor runs first, b copies a while a is still undef. A number initializer is folded to a constant, which is why number globals are unaffected.
Possible fixes:
give each initializer a priority that follows declaration order;
run all of a module's initializers from one function, in declaration order.
Activity
-mm=own phase 6: spec 20.5 cites #446-#448
-mm=own phase 6: the corpus report; globals' initializers, data nothi…
-mm=own phase 8: Shared<T> (spec 23) (#463)
A global initialised from another global runs after it (#446) (#476)
A global copied from another global, or from a field, takes a count (#…