https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90079
Bug ID: 90079 Summary: SEGV in _aaKeys, _aaValues on 32-bit SPARC Product: gcc Version: 9.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: d Assignee: ibuclaw at gdcproject dot org Reporter: ro at gcc dot gnu.org Target Milestone: --- Target: sparc*-*-* Created attachment 46161 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=46161&action=edit Trial patch All aa tests currently SEGV on 32-bit Solaris/SPARC, e.g. FAIL: libphobos.aa/test_aa.d execution test Thread 2 received signal SIGSEGV, Segmentation fault. [Switching to Thread 1 (LWP 1)] 0x0009c9b0 in rt.aaA.Impl.length() const (this=...) at /vol/gcc/src/hg/trunk/solaris/libphobos/libdruntime/rt/aaA.d:87 87 assert(used >= deleted); (gdb) where #0 0x0009c9b0 in rt.aaA.Impl.length() const (this=...) at /vol/gcc/src/hg/trunk/solaris/libphobos/libdruntime/rt/aaA.d:87 #1 0x0009c960 in rt.aaA.AA.empty() const (this=...) at /vol/gcc/src/hg/trunk/solaris/libphobos/libdruntime/rt/aaA.d:44 #2 0x0009e83c in _aaValues (aa=..., keysz=4, valsz=1, tiValueArray=0x718fc <initializer for TypeInfo_AS7test_aa15testKeysValues1FZ1T>) at /vol/gcc/src/hg/trunk/solaris/libphobos/libdruntime/rt/aaA.d:513 #3 0x00082688 in object.values!(test_aa.testKeysValues1().T[int], test_aa.testKeysValues1().T, int).values(test_aa.testKeysValues1().T[int]) (aa=...) at /vol/gcc/src/hg/trunk/solaris/libphobos/libdruntime/object.d:2171 #4 0x00077a9c in test_aa.testKeysValues1() () at /vol/gcc/src/hg/trunk/solaris/libphobos/testsuite/libphobos.aa/test_aa.d:56 #5 0x00077604 in D main () at /vol/gcc/src/hg/trunk/solaris/libphobos/testsuite/libphobos.aa/test_aa.d:3 1: x/i $pc => 0x9c9b0 <_D2rt3aaA4Impl6lengthMxFNaNbNdNiZk+32>: ld [ %g1 + 8 ], %g2 (gdb) p/x $g1 $1 = 0x8 (gdb) up #1 0x0009c960 in rt.aaA.AA.empty() const (this=...) at /vol/gcc/src/hg/trunk/solaris/libphobos/libdruntime/rt/aaA.d:44 44 return impl is null || !impl.length; (gdb) p impl $2 = (rt.aaA.Impl *) 0x8 (gdb) up #2 0x0009e864 in _aaValues (aa=..., keysz=4, valsz=1, tiValueArray=0x718fc <initializer for TypeInfo_AS7test_aa15testKeysValues1FZ1T>) at /vol/gcc/src/hg/trunk/solaris/libphobos/libdruntime/rt/aaA.d:513 513 if (aa.empty) (gdb) p aa $2 = {impl = 0x8} (gdb) up #3 0x000826b0 in object.values!(test_aa.testKeysValues1().T[int], test_aa.testKeysValues1().T, int).values(test_aa.testKeysValues1().T[int]) (aa=...) at /vol/gcc/src/hg/trunk/solaris/libphobos/libdruntime/object.d:2171 2171 auto a = cast(void[])_aaValues(cast(inout(void)*)aa, Key.sizeof, Value.sizeof, typeid(Value[])); (gdb) p aa $3 = {ptr = 0xfef11000} Closer investigation reveals object.d calls _aaValues (and _aaKeys) incorrectly: While the implementation expects a struct AA libdruntime/rt/aaA.d:extern (C) inout(void[]) _aaValues(inout AA aa, in size_t keysz, in size_t valsz, the call passes a void * instead: libdruntime/object.d: inout(void)[] _aaValues(inout void* p, in size_t keysize, in size_t valuesize, const TypeInfo tiValArray) pure nothrow; libdruntime/object.d: auto a = cast(void[])_aaValues(cast(inout(void)*)aa, Key.sizeof, Value.sizeof, typeid(Value[])); The problem is that on 32-bit SPARC small structs are passed by reference, so there's a mismatch between caller and callee. On 64-bit SPARC instead, they are passed by value, so the mismatch doesn't matter and the tests PASS. So far, I've not yet managed to figure out the correct way to fix this, though: while the attached patch allows libdruntime to compile, test_aa.d fails: libdruntime/object.d:2172: error: cannot cast expression aa of type T[int] to inout(AA) testsuite/libphobos.aa/test_aa.d:56: error: template instance object.values!(T[int], T, int) error instantiating libdruntime/object.d:2150: error: cannot cast expression aa of type int[T] to inout(AA) testsuite/libphobos.aa/test_aa.d:66: error: template instance object.keys!(int[T], int, T) error instantiating libdruntime/object.d:2150: error: cannot cast expression aa of type int[string] to inout(AA) testsuite/libphobos.aa/test_aa.d:75: error: template instance object.keys!(int[string], int, string) error instantiating libdruntime/object.d:2172: error: cannot cast expression aa of type int[string] to inout(AA)