Bug 15422 – [REG2.066] associative array of nested struct - crash on usage

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-12-08T15:31:00Z
Last change time
2016-02-01T17:14:23Z
Keywords
pull, wrong-code
Assigned to
nobody
Creator
dfj1esp02

Comments

Comment #0 by dfj1esp02 — 2015-12-08T15:31:05Z
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 } } int main() { App a = new App; a.crash( 1 ); return 0; } Works on dmd 2.064.2
Comment #1 by gassa — 2015-12-09T12:18:19Z
Able to reproduce this on win32/win64. Original D.learn forum thread is mentioned in URL. An extract from there: With dmd 2.064.2, the 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 dmd 2.069.2, it compiles fine but crashes at runtime. So I'd say it's a regression somewhere between 2.064 and 2.066.
Comment #2 by k.hara.pg — 2015-12-09T14:39:38Z
Introduced in: https://github.com/d-programming-language/dmd/commit/a2f9ddf4eb7d5ffeb4bb157d5dcda9efe2f5b290 The main problem is that, built-in generated hashing operations don't handle hidden context field (foo.tupleof[$-1]) properly. I discovered that built-in generated equality operations also have equivalent issue.
Comment #3 by k.hara.pg — 2015-12-09T15:42:57Z
(In reply to Ivan Kazmenko from comment #1) > 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 dmd 2.069.2, it compiles > fine but crashes at runtime. > > So I'd say it's a regression somewhere between 2.064 and 2.066. The guilty commit had been introduced in 2.065, but the actual problem had been hidden until 2.066 was released, by the compiler's "no opCmp" complaint. PR to fix the issue: https://github.com/D-Programming-Language/dmd/pull/5304
Comment #4 by k.hara.pg — 2015-12-14T15:29:09Z
Comment #5 by github-bugzilla — 2016-02-01T17:14:22Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/d789012d8630619ee34a680724e4f4ca1e4f091b fix Issue 15422 - associative array of nested struct - crash on usage If a struct is nested in a class, its `vthis` will be reference to the parent class, and struct default equality and hashing considers the parent class equality and hashing. Otherwise, the `vthis` will be typed as void*, and pointer equality and hashing is merely used. https://github.com/D-Programming-Language/dmd/commit/92b3fead80829a3dd4e8618dc5533bd62b1f455c Merge pull request #5391 from 9rnsr/fix15422 [REG2.066] Issue 15422 - associative array of nested struct - crash on usage