Bug 24440 – [REG 2.107] multiple multidimensional array appends broke in 2.107

Status
RESOLVED
Resolution
DUPLICATE
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2024-03-17T15:02:22Z
Last change time
2024-04-19T18:57:43Z
Assigned to
No Owner
Creator
Ivan Kazmenko

Attachments

IDFilenameSummaryContent-TypeSize
1911reg107.dreduced exampletext/plain161

Comments

Comment #0 by gassa — 2024-03-17T15:02:22Z
Reduced example: ``` immutable int n = 500; void main() { auto a = new long [] [] [] (n, n); foreach (i; 0..n * 4) foreach (j; 0..n) a[j][0] ~= 0; assert(false); } ``` Compile string (Windows): `dmd -m32 -g reg107.d` or `dmd -m64 -g reg107.d` Expected behavior (works in 2.106.0): The program correctly goes to `assert(false)` and halts there. This way is used instead of debug output to avoid libraries. Issue (in 2.107.0, 2.107.1, and 2.108.0-rc1): The Win32 build breaks with: ``` object.Error@(0): Win32 Exception ---------------- 0x740CF41C in wcslen 0x00401101 in D main at C:\programs\stuff\dmd\reg107.d(6) 0x004042CF in void rt.dmain2._d_run_main2(char[][], uint, extern (C) int function(char[][])*).runAll().__lambda2() ... ``` The Win64 build just breaks silently. Issue was reported on Linux too, but I can't check there at the moment.
Comment #1 by gassa — 2024-03-17T15:03:23Z
Created attachment 1911 reduced example
Comment #2 by gassa — 2024-03-31T22:02:57Z
With Linux, it's just "segmentation fault" with 2.107. Correctly goes to assert(false) with 2.106.
Comment #3 by gassa — 2024-03-31T22:09:49Z
Originally got hit by it in my toy language project which I use to teach parallel computing. It maintains a three-dimensional array to store queues of messages between different simulated processes. For now, circumvented the issue by transforming it to a two-dimensional array of structs containing arrays. https://github.com/GassaFM/interpr/commit/b959bb7870 Still, multidimensional arrays are a pretty core language feature. Can I expect it would work again at some point?.. Ivan Kazmenko.
Comment #4 by hos — 2024-04-19T17:30:58Z
Sorry if this is unrelated, but I'm trying to add an example with similar behavior. The following code, given `1000 1000` on the first line and 1000 tokens in each of the subsequence 1000 lines from standard input, fails to run successfully and it is just "Segmentation fault" (DMD>=2.107.0, WSL2). ``` import std.conv, std.stdio, std.string; void main() { string[] tokens = readln.chomp.split; const M = tokens[0].to!int; const N = tokens[1].to!int; auto A = new string[][](M, N); foreach (x; 0 .. M) { tokens = readln.chomp.split; foreach (y; 0 .. N) { A[x][y] = tokens[y]; } } } ``` For further info, I found this at when solving a problem at https://yukicoder.me/ - my submission link: https://yukicoder.me/submissions/974786 where I see that when the input is smaller the segmentation fault does not happen (RE (Runtime Error) vs WA (Wrong Answer)).
Comment #5 by tim.dlang — 2024-04-19T18:57:16Z
This looks like the same problem as in issue 24498. The expression `new long [][][](n, n)` creates memory, which is not scanned by the GC, but contains pointers. The GC will free the inner arrays and the program crashes, when they are accessed.
Comment #6 by tim.dlang — 2024-04-19T18:57:43Z
*** This issue has been marked as a duplicate of issue 24498 ***