www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - AA struct hashing bug?

reply Random D user <no email.com> writes:
struct Foo
{
     this( int k )
     {
         a = k;
     }
     int a;
}

Foo foo;
int[ Foo ] map;

map[ foo ] = 1;  // Crash! bug?

// This also crashes. I believe crash above makes a call like 
this (or similar) in the rt.
//auto h = typeid( foo ).getHash( &foo ); // Crash!

win64 & dmd 2.69.2
Dec 07 2015
next sibling parent ketmar <ketmar ketmar.no-ip.org> writes:
worksforme. git HEAD, GNU/Linux, x86.
Dec 07 2015
prev sibling parent reply Alex Parrill <initrd.gz gmail.com> writes:
On Monday, 7 December 2015 at 18:48:18 UTC, Random D user wrote:
 struct Foo
 {
     this( int k )
     {
         a = k;
     }
     int a;
 }

 Foo foo;
 int[ Foo ] map;

 map[ foo ] = 1;  // Crash! bug?

 // This also crashes. I believe crash above makes a call like 
 this (or similar) in the rt.
 //auto h = typeid( foo ).getHash( &foo ); // Crash!

 win64 & dmd 2.69.2
Also works on DMD v2.069.2 on XUbuntu Linux x64. I can try it on Windows later. Exact code I tested: struct Foo { this( int k ) { a = k; } int a; } void main() { Foo foo; int[ Foo ] map; map[ foo ] = 1; }
Dec 07 2015
parent reply Ivan Kazmenko <gassa mail.ru> writes:
On Monday, 7 December 2015 at 22:03:42 UTC, Alex Parrill wrote:
 On Monday, 7 December 2015 at 18:48:18 UTC, Random D user wrote:
 struct Foo
 {
     this( int k )
     {
         a = k;
     }
     int a;
 }

 Foo foo;
 int[ Foo ] map;

 map[ foo ] = 1;  // Crash! bug?

 // This also crashes. I believe crash above makes a call like 
 this (or similar) in the rt.
 //auto h = typeid( foo ).getHash( &foo ); // Crash!

 win64 & dmd 2.69.2
Also works on DMD v2.069.2 on XUbuntu Linux x64. I can try it on Windows later. Exact code I tested: struct Foo { this( int k ) { a = k; } int a; } void main() { Foo foo; int[ Foo ] map; map[ foo ] = 1; }
Tested the same code with -m32 and -m64 on Windows. Works for me, too.
Dec 07 2015
parent reply Random D user <no email.com> writes:
On Tuesday, 8 December 2015 at 01:23:40 UTC, Ivan Kazmenko wrote:
 On Monday, 7 December 2015 at 22:03:42 UTC, Alex Parrill wrote:
 On Monday, 7 December 2015 at 18:48:18 UTC, Random D user
Tested the same code with -m32 and -m64 on Windows. Works for me, too.
I tried this again. And it seems it might be my bug or that the runtime somehow corrupts it's state. Scary. So I have an App class that gets created in main. Basically App = new App App.start(); If I put that code as the first thing in the constructor everything works. If I put that code as the first thing in the first method after constructor it crashes. And that code is completely unrelated to everything else. Without the code snippet the whole app works fine. Also if I wrap the code in a local funtion or class, it works fine even in the first method. I need to look into this more.
Dec 08 2015
next sibling parent reply Random D user <no email.com> writes:
On Tuesday, 8 December 2015 at 11:04:49 UTC, Random D user wrote:
 I need to look into this more.
Ok. This is minimal app that crashes for me. If someone could try this: class App { this() { } void crash( int val ) in { assert( val == 1 ); } body { struct Foo { this( int k ) { a = k; } int a; } Foo foo; int[ Foo ] map; map[ foo ] = 1; // Crash! bug? } } int main( char[][] args ) { App a = new App; a.crash( 1 ); return 0; } And the previous case for the crash looks like this: asm: _D6object14TypeInfo_Class7getHashMxFNbNexPvZm: 00007ff6d9e4b500 push rbp 00007ff6d9e4b501 mov rbp, rsp 00007ff6d9e4b504 sub rsp, 0x30 00007ff6d9e4b508 mov [rbp-0x8], rsi 00007ff6d9e4b50c mov rsi, [rdx] 00007ff6d9e4b50f test rsi, rsi 00007ff6d9e4b512 jz _D6object14TypeInfo_Class7getHashMxFNbNexPvZm+0x20 (0x7ff6d9e4b520) 00007ff6d9e4b514 mov rcx, rsi 00007ff6d9e4b517 mov rax, [rsi] 00007ff6d9e4b51a call qword near [rax+0x10] <---------------- crash here 00007ff6d9e4b51e jmp _D6object14TypeInfo_Class7getHashMxFNbNexPvZm+0x22 (0x7ff6d9e4b522) 00007ff6d9e4b520 xor eax, eax 00007ff6d9e4b522 mov rsi, [rbp-0x8] 00007ff6d9e4b526 lea rsp, [rbp] 00007ff6d9e4b52a pop rbp stack: 0000000000000000 _D6object14TypeInfo_Class7getHashMxFNbNexPvZm() + 0x1e bytes D _D6object14TypeInfo_Const7getHashMxFNbNfxPvZm() + 0x13 bytes D application.Application.startup.Foo.__xtoHash( application.Application.startup.Foo* p, ulong h ) + 0x55 bytes D _D6object15TypeInfo_Struct7getHashMxFNaNbNfxPvZm() + 0x22 bytes D _aaGetY() + 0xa0 bytes D application.Application.startup() Line 159 + 0x26 bytes D
Dec 08 2015
next sibling parent Ivan Kazmenko <gassa mail.ru> writes:
On Tuesday, 8 December 2015 at 11:45:25 UTC, Random D user wrote:
 Ok. This is minimal app that crashes for me. If someone could 
 try this:
OK, this at least reproducibly crashes here, too (-m32 and -m64 on Windows, tried dmd 2.069.0 and 2.067.1).
Dec 08 2015
prev sibling next sibling parent Ivan Kazmenko <gassa mail.ru> writes:
On Tuesday, 8 December 2015 at 11:45:25 UTC, Random D user wrote:
 Ok. This is minimal app that crashes for me. If someone could 
 try this:
At the very least, there is no crash when changing `struct Foo` to `static struct Foo`, so it is perhaps related to `Foo` being an inner struct with a pointer to parent class.
Dec 08 2015
prev sibling next sibling parent Ivan Kazmenko <gassa mail.ru> writes:
On Tuesday, 8 December 2015 at 11:45:25 UTC, Random D user wrote:
 Ok. This is minimal app that crashes for me. If someone could 
 try this:
Interesting. With dmd 2.064.2, your example compiles and runs fine. With dmd 2.065.0, it does not compile, complaining that there is no opCmp for `Foo`s. With dmd 2.066.0, and up to the current version, it compiles fine but crashes at runtime. So I'd say it's a regression. The tracker at issues.dlang.org does not report much bugs related to inner structs. Can you please file a new issue there?
Dec 08 2015
prev sibling parent ketmar <ketmar ketmar.no-ip.org> writes:
heh. it crashed due to "in" presence. if you'll remove "in", it 
will work.
Dec 09 2015
prev sibling parent Ivan Kazmenko <gassa mail.ru> writes:
On Tuesday, 8 December 2015 at 11:04:49 UTC, Random D user wrote:
 On Tuesday, 8 December 2015 at 01:23:40 UTC, Ivan Kazmenko 
 wrote:
 On Monday, 7 December 2015 at 22:03:42 UTC, Alex Parrill wrote:
 On Monday, 7 December 2015 at 18:48:18 UTC, Random D user
Tested the same code with -m32 and -m64 on Windows. Works for me, too.
I tried this again. And it seems it might be my bug or that the runtime somehow corrupts it's state. Scary. So I have an App class that gets created in main. Basically App = new App App.start(); If I put that code as the first thing in the constructor everything works. If I put that code as the first thing in the first method after constructor it crashes. And that code is completely unrelated to everything else. Without the code snippet the whole app works fine. Also if I wrap the code in a local funtion or class, it works fine even in the first method.
Well, if you manage to reduce the code to a minimal example reproducing the bug, and then post it, only then we can try to help. Otherwise, other people will have nothing but guesses.
Dec 08 2015