Bug 18412 – [REG2.077.0] immutable array in library becomes null when referenced in static constructor
Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P5
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2018-02-09T23:27:15Z
Last change time
2020-09-20T17:06:27Z
Keywords
backend, pull, wrong-code
Assigned to
No Owner
Creator
ag0aep6g
Comments
Comment #0 by ag0aep6g — 2018-02-09T23:27:15Z
Spin-off from issue 18403.
m1.d:
----
import m2: f;
void main() { f(); }
----
m2.d:
----
static this()
{
auto k = keywords;
}
immutable int[] keywords = [42];
void f()
{
assert(keywords.ptr !is null); /* fails; should pass */
}
----
Compile and run (Windows via Wine, DMD32 D Compiler v2.077.0):
----
dmd -lib m2.d
dmd m1.d m2.lib
./m1.exe
----
Works with 2.076.1. Works on Linux. Works when the array is mutable. Works when the array is declared before the static constructor.
Comment #1 by iamthewilsonator — 2018-02-11T09:06:41Z
This also happens with delegates and is the root cause for https://github.com/libmir/dcompute/issues/32
This affects ldc as well so this is a frontend issue, I can't remember if I was using 32 or 64 bit (I won't have access to that machine for another week).
(In reply to Nicholas Wilson from comment #3)
> Hmm all dmd backend code?
> I wonder what the cause of null delegates with LDC is then?
Dare to bisect LDC? Or at least figure out which ldc version introduced it?
Might be independent bugs after all.
Comment #5 by bugzilla — 2020-09-05T09:57:15Z
If I create the .obj file with:
dmd -c m2
and link the program works. If I create it with:
dmd -lib m2
lib m2 *m2.obj;
and link the program fails. Examining the two object files, the entire static constructor is missing from the second one. The two object files should be identical.
Comment #6 by bugzilla — 2020-09-05T10:33:16Z
Actually, that's wrong.
dmd -lib m2.d
puts two object files in the library, m2.obj and m2_1_66.obj. The second one is the missing code - but it's reference to keywords should be an extern, but is not, just an unnamed static datum past the end of the data segment (!).
Apparently the code that resets the external references between object module generation broke, which is consistent with the PR that caused the regression:
https://github.com/dlang/dmd/pull/7150
Comment #7 by dlang-bot — 2020-09-06T05:30:38Z
@WalterBright created dlang/dmd pull request #11695 "fix Issue 18412 - [REG2.077.0] immutable array in library becomes nul…" fixing this issue:
- fix Issue 18412 - [REG2.077.0] immutable array in library becomes null when referenced in static constructor
https://github.com/dlang/dmd/pull/11695
Comment #8 by dlang-bot — 2020-09-11T09:00:20Z
dlang/dmd pull request #11695 "fix Issue 18412 - [REG2.077.0] immutable array in library becomes nul…" was merged into stable:
- c737edf822e5dd3a48875a5eb704b94852dd6925 by Walter Bright:
fix Issue 18412 - [REG2.077.0] immutable array in library becomes null when referenced in static constructor
https://github.com/dlang/dmd/pull/11695
Comment #9 by dlang-bot — 2020-09-20T17:06:27Z
dlang/dmd pull request #11759 "merge stable" was merged into master:
- d1344a33cf293bea0c048498d0ffcc5460ba2c3e by Walter Bright:
fix Issue 18412 - [REG2.077.0] immutable array in library becomes null when referenced in static constructor
https://github.com/dlang/dmd/pull/11759