D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 15422 - [REG2.066] associative array of nested struct - crash on usage
Summary: [REG2.066] associative array of nested struct - crash on usage
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 regression
Assignee: No Owner
URL: http://forum.dlang.org/post/mufvqrqgk...
Keywords: pull, wrong-code
Depends on:
Blocks:
 
Reported: 2015-12-08 15:31 UTC by anonymous4
Modified: 2016-02-01 17:14 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description anonymous4 2015-12-08 15:31:05 UTC
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 Ivan Kazmenko 2015-12-09 12:18:19 UTC
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 Kenji Hara 2015-12-09 14:39:38 UTC
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 Kenji Hara 2015-12-09 15:42:57 UTC
(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 Kenji Hara 2015-12-14 15:29:09 UTC
New PR: https://github.com/D-Programming-Language/dmd/pull/5308
Comment 5 github-bugzilla 2016-02-01 17:14:22 UTC
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