Bug 23024 – Large static array causes access violation on Windows with DMD
Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2022-04-17T02:28:23Z
Last change time
2023-05-05T08:25:03Z
Keywords
pull
Assigned to
No Owner
Creator
andy.pj.hanson
Comments
Comment #0 by andy.pj.hanson — 2022-04-17T02:28:23Z
This program breaks on Windows when compiled with DMD:
```
import core.stdc.stdio : printf;
static ulong[0x100000] data;
extern(C) void main() {
foreach (immutable size_t i; 0 .. data.length) {
printf("Write to data[%llu]\n", i);
data[i] = 42;
}
printf("Success\n");
}
```
The issue is an access violation.
`dmd -m64 a.d && .\a.exe` fails before writing data[1007].
`dmd -m64 -g a.d && .\a.exe` fails before writing data[6].
(Removing the -m64 doesn't help. The difference with `-g` may be related to https://issues.dlang.org/show_bug.cgi?id=21763 .)
`ldc2 a.d && .\a.exe` succeeds. And both dmd and ldc2 work on Linux.
I'm testing this on a VMWare virtual machine in case that matters.
Tested with dmd `v2.099.1-dirty`.
Comment #1 by dlang-bot — 2023-05-02T22:09:22Z
@rainers created dlang/dmd pull request #15170 "fix issues 20737 and 23024 - TLS variables unusable with -betterC/imp…" fixing this issue:
- fix issues 20737 and 23024 - TLS variables unusable with -betterC/importC for Windows MSVC targets
always generate access via __tls_index
https://github.com/dlang/dmd/pull/15170
Comment #2 by bugzilla — 2023-05-05T08:25:03Z
The fix has been merged, so I'm marking this as fixed.