www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 9427] New: wrong code for 'struct S{ union{ float[2] f; } }'

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9427

           Summary: wrong code for 'struct S{ union{ float[2] f; } }'
           Product: D
           Version: D2
          Platform: x86_64
        OS/Version: Linux
            Status: NEW
          Severity: critical
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: manuelk89 gmx.net



file test.d
-------------------------
import std.stdio;

struct S
{
    union { int[2] i; }
}

void test_S(S s)
{
    writeln(s.i);        // should print [3,0], but prints "random numbers"
    assert(s.i[0] == 3); // should pass, but fails -- (line 11)
}

void main()
{   
    S s;
    s.i[0] = 3;

    writeln(s.i);        // prints [3, 0], as expected
    assert(s.i[0] == 3); // passes, as expected

    test_S(s);
}
-------------------------
$ dmd test.d
$ ./test
[3, 0]
[1657017216, 32767]
core.exception.AssertError test(11): Assertion failure
[...]
-------------------------

The error does not occur for different array sizes of int[2] i; (testet for
1,3,4,5). I guess this is some x86_64 specific codegen error. Relevant
disassembly obtained with 'objdump -S test':

-------------------------
0000000000421090 <_D4test6test_SFS4test1SZv>:
  421090:   55                      push   %rbp
  421091:   48 8b ec                mov    %rsp,%rbp
  421094:   48 8b 7d 10             mov    0x10(%rbp),%rdi
  421098:   e8 5b 00 00 00          callq  4210f8
<_D3std5stdio16__T7writelnTG2iZ7writelnFG2iZv>
  42109d:   8b 45 10                mov    0x10(%rbp),%eax
  4210a0:   83 f8 03                cmp    $0x3,%eax
  4210a3:   74 0a                   je     4210af
<_D4test6test_SFS4test1SZv+0x1f>
  4210a5:   bf 0b 00 00 00          mov    $0xb,%edi
  4210aa:   e8 31 81 00 00          callq  4291e0 <_D4test8__assertFiZv>
  4210af:   5d                      pop    %rbp
  4210b0:   c3                      retq   
  4210b1:   90                      nop
  4210b2:   90                      nop
  4210b3:   90                      nop

00000000004210b4 <_Dmain>:
  4210b4:   55                      push   %rbp
  4210b5:   48 8b ec                mov    %rsp,%rbp
  4210b8:   48 83 ec 08             sub    $0x8,%rsp
  4210bc:   53                      push   %rbx
  4210bd:   48 8d 45 f8             lea    -0x8(%rbp),%rax
  4210c1:   48 31 c9                xor    %rcx,%rcx
  4210c4:   48 89 08                mov    %rcx,(%rax)
  4210c7:   ba 03 00 00 00          mov    $0x3,%edx
  4210cc:   89 55 f8                mov    %edx,-0x8(%rbp)
  4210cf:   48 8b 7d f8             mov    -0x8(%rbp),%rdi
  4210d3:   e8 20 00 00 00          callq  4210f8
<_D3std5stdio16__T7writelnTG2iZ7writelnFG2iZv>
  4210d8:   8b 5d f8                mov    -0x8(%rbp),%ebx
  4210db:   83 fb 03                cmp    $0x3,%ebx
  4210de:   74 0a                   je     4210ea <_Dmain+0x36>
  4210e0:   bf 14 00 00 00          mov    $0x14,%edi
  4210e5:   e8 f6 80 00 00          callq  4291e0 <_D4test8__assertFiZv>
  4210ea:   48 8b 7d f8             mov    -0x8(%rbp),%rdi
  4210ee:   e8 9d ff ff ff          callq  421090 <_D4test6test_SFS4test1SZv>
  4210f3:   31 c0                   xor    %eax,%eax
  4210f5:   5b                      pop    %rbx
  4210f6:   c9                      leaveq 
  4210f7:   c3                      retq

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 30 2013
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9427


Maxim Fomin <maxim maxim-fomin.ru> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |maxim maxim-fomin.ru
         Resolution|                            |WORKSFORME



---
Works in linux 2.063 beta.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 18 2013