Bug 1741 – crash on associative array with static array as index type
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Linux
Creation time
2007-12-18T07:07:00Z
Last change time
2014-02-24T15:32:08Z
Keywords
wrong-code
Assigned to
bugzilla
Creator
georg
Comments
Comment #0 by georg — 2007-12-18T07:07:54Z
The associative array implementation causes a segmentation fault when used with a static array as the key type.
The nice guys on #D helped me to trace the problem to the following point:
The implementation crashes in uint std.typeinfo.ti_Ag.TypeInfo_Ag.getHash(void*), which is actually meant for dynamic arrays, so it seems the wrong TypeInfo is referenced, and thus the memory access in getHash() fails.
The following code triggers the problem for me (you have to initialize key with !=0):
int main() {
ubyte[4] key = 23;
int[ubyte[4]] aa;
aa[key] = 42;
/* this point is never reached */
return 0;
}
A workaround is to use dynamic arrays (less efficient because of an added level of redirection) or to encapsulate the static array into a struct (less readable, but working).
The problem can also be reproduced with gdc [gcc version 4.1.3 20071209 (prerelease gdc 0.25 20071124, using dmd 1.022) (Debian 0.25-4.1.2-18)].
Comment #1 by jason — 2008-04-02T03:39:51Z
This still occurs with dmd version 1.028
user@vm-fruitbat:~$ dmd -g t.d
user@vm-fruitbat:~$ gdb t
GNU gdb 6.6-debian
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i486-linux-gnu"...
Using host libthread_db library "/lib/tls/i686/cmov/libthread_db.so.1".
(gdb) run
Starting program: /home/user/t
[Thread debugging using libthread_db enabled]
[New Thread -1209919824 (LWP 12717)]
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread -1209919824 (LWP 12717)]
0x08053906 in _D3std8typeinfo5ti_Ag11TypeInfo_Ag7getHashMFPvZk ()
(gdb) bt
#0 0x08053906 in _D3std8typeinfo5ti_Ag11TypeInfo_Ag7getHashMFPvZk ()
#1 0x0804a8d1 in _aaGet ()
Die: DW_TAG_<unknown> (abbrev = 6, offset = 505)
has children: FALSE
attributes:
DW_AT_byte_size (DW_FORM_data1) constant: 4
DW_AT_type (DW_FORM_ref4) constant ref: 340 (adjusted)
DW_AT_containing_type (DW_FORM_ref4) constant ref: 486 (adjusted)
Dwarf Error: Cannot find type of die [in module /home/user/t]