Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
January 13, 2010 [Issue 3700] New: Ref foreach over large static arrays fails | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=3700 Summary: Ref foreach over large static arrays fails Product: D Version: 2.038 Platform: Other OS/Version: Linux Status: NEW Severity: major Priority: P2 Component: DMD AssignedTo: nobody@puremagic.com ReportedBy: bugzilla@kyllingen.net --- Comment #0 from Lars T. Kyllingstad <bugzilla@kyllingen.net> 2010-01-13 00:21:30 PST --- This code correctly compiles, but causes a segmentation fault when run: void main() { double[1_000_000] a; foreach (ref e; a) e = 1.0; } In case it helps, here's a disassembly of the main function. A run through the debugger shows that the offending instruction is located at 0x080490cd. 080490c4 <_Dmain>: 80490c4: 55 push %ebp 80490c5: 8b ec mov %esp,%ebp 80490c7: 81 ec 1c 24 f4 00 sub $0xf4241c,%esp 80490cd: 53 push %ebx 80490ce: 57 push %edi 80490cf: b9 80 84 1e 00 mov $0x1e8480,%ecx 80490d4: 31 c0 xor %eax,%eax 80490d6: 8d bd e4 db 0b ff lea -0xf4241c(%ebp),%edi 80490dc: f3 ab rep stos %eax,%es:(%edi) 80490de: 8d 8d e4 db 0b ff lea -0xf4241c(%ebp),%ecx 80490e4: bb 40 42 0f 00 mov $0xf4240,%ebx 80490e9: 89 9d e4 ed 85 ff mov %ebx,-0x7a121c(%ebp) 80490ef: 89 8d e8 ed 85 ff mov %ecx,-0x7a1218(%ebp) 80490f5: 89 85 ec ed 85 ff mov %eax,-0x7a1214(%ebp) 80490fb: 8b 95 ec ed 85 ff mov -0x7a1214(%ebp),%edx 8049101: 3b 95 e4 ed 85 ff cmp -0x7a121c(%ebp),%edx 8049107: 73 42 jae 804914b <_Dmain+0x87> 8049109: 8b 85 ec ed 85 ff mov -0x7a1214(%ebp),%eax 804910f: 3b 85 e4 ed 85 ff cmp -0x7a121c(%ebp),%eax 8049115: 72 0a jb 8049121 <_Dmain+0x5d> 8049117: b8 04 00 00 00 mov $0x4,%eax 804911c: e8 33 00 00 00 call 8049154 <_D1d7__arrayZ> 8049121: 8b 8d ec ed 85 ff mov -0x7a1214(%ebp),%ecx 8049127: 8b 95 e8 ed 85 ff mov -0x7a1218(%ebp),%edx 804912d: 8b 85 e4 ed 85 ff mov -0x7a121c(%ebp),%eax 8049133: 8d 1c ca lea (%edx,%ecx,8),%ebx 8049136: c7 03 00 00 00 00 movl $0x0,(%ebx) 804913c: c7 43 04 00 00 f0 3f movl $0x3ff00000,0x4(%ebx) 8049143: ff 85 ec ed 85 ff incl -0x7a1214(%ebp) 8049149: eb b0 jmp 80490fb <_Dmain+0x37> 804914b: 31 c0 xor %eax,%eax 804914d: 5f pop %edi 804914e: 5b pop %ebx 804914f: c9 leave 8049150: c3 ret 8049151: 90 nop 8049152: 90 nop 8049153: 90 nop -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
January 14, 2010 [Issue 3700] Ref foreach over large static arrays fails | ||||
---|---|---|---|---|
| ||||
Posted in reply to Lars T. Kyllingstad | http://d.puremagic.com/issues/show_bug.cgi?id=3700 Don <clugdbug@yahoo.com.au> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED CC| |clugdbug@yahoo.com.au Resolution| |INVALID --- Comment #1 from Don <clugdbug@yahoo.com.au> 2010-01-14 06:41:44 PST --- Nothing to do with foreach. It's just a stack overflow. Reduced test case: void main() { double[1000000] a; } Error: Stack Overflow You can't expect 8Mb of data to be storable on the stack! This will happen in C, as well. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
January 14, 2010 [Issue 3700] Ref foreach over large static arrays fails | ||||
---|---|---|---|---|
| ||||
Posted in reply to Lars T. Kyllingstad | http://d.puremagic.com/issues/show_bug.cgi?id=3700 --- Comment #2 from Lars T. Kyllingstad <bugzilla@kyllingen.net> 2010-01-14 06:56:27 PST --- You may be right. But consider the following: * The "Arrays" page on the D homepage says that "The total size of a static array cannot exceed 16Mb." I am only allocating half of that. * When I've run my example, it has *always* caused a segmentation fault. * The following, on the other hand, has so far *never* caused a segmentation fault on my machine: void main() { double[1_000_000] a; for (i; 0 .. a.length) a[i] = 1.0; } -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
January 14, 2010 [Issue 3700] Ref foreach over large static arrays fails | ||||
---|---|---|---|---|
| ||||
Posted in reply to Lars T. Kyllingstad | http://d.puremagic.com/issues/show_bug.cgi?id=3700 Leandro Lucarella <llucax@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |llucax@gmail.com --- Comment #3 from Leandro Lucarella <llucax@gmail.com> 2010-01-14 07:40:02 PST --- In Linux the default stack size is 8MiB, I don't think D runtime changes that. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
January 14, 2010 [Issue 3700] Ref foreach over large static arrays fails | ||||
---|---|---|---|---|
| ||||
Posted in reply to Lars T. Kyllingstad | http://d.puremagic.com/issues/show_bug.cgi?id=3700 --- Comment #4 from Don <clugdbug@yahoo.com.au> 2010-01-14 09:05:21 PST --- (In reply to comment #2) > You may be right. But consider the following: > > * The "Arrays" page on the D homepage says that "The total size of a static array cannot exceed 16Mb." I am only allocating half of that. That limit is for static arrays (ie, global arrays, or arrays marked 'static'), not fixed-length arrays. (I wish the spec would stop talking about 'static arrays' when it means 'fixed-length'). The size of the stack is always limited by the OS, sometimes severely so. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
Copyright © 1999-2021 by the D Language Foundation