[Issue 3914] New: Struct as argument that fits in register has member accessed wrong

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Mar 9 10:54:35 PST 2010


http://d.puremagic.com/issues/show_bug.cgi?id=3914

           Summary: Struct as argument that fits in register has member
                    accessed wrong
           Product: D
           Version: 2.041
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: crimson.magus at gmail.com


--- Comment #0 from Aldo Nunez <crimson.magus at gmail.com> 2010-03-09 10:54:31 PST ---
Depending on the build options and where in a function the struct parameter is
used, referencing one member will actually reference another one.

Given the following program:

import std.stdio;

struct SS
{
    char a;
    char b;
    char c;
    char d;
//    char e;
}

void A( SS ss1 )
{
C:    //writeln( ss1.a, ss1.b, ss1.c, ss1.d );

    char temp;

    temp = ss1.a;
    ss1.a = ss1.d;
    ss1.d = temp;

    temp = ss1.b;
    ss1.b = ss1.c;
    ss1.c = temp;

B:    //writeln( ss1.a, ss1.b, ss1.c, ss1.d );

    temp = ss1.a;
    ss1.a = ss1.d;
    ss1.d = temp;

    temp = ss1.b;
    ss1.b = ss1.c;
    ss1.c = temp;

A:    writeln( ss1.a, ss1.b, ss1.c, ss1.d );
}

void main()
{
    SS ss3;

    ss3.a = 'A';
    ss3.b = 'L';
    ss3.c = 'D';
    ss3.d = 'O';

    A( ss3 );
}

If lines A, B, and C are enabled in the following pattern along with the given
build options, you get these results:

    (none)    -g    -rel    -rel-O    -O    -g -O
A    ALDO    ALDO    ALDO    ALDA    ALDA    ALDA

B, A    ODLA    ODLA    ODLA    ADLA    ADLA    ADLA
    ALDO    ALDO    ALDO    ALDA    ALDA    ALDA

C, B, A    ALDA    ALDO    ALDA    ALDA    ALDA    ALDA
    ODLA    ODLA    ODLA    ODLA    ODLA    ODLA
    ALDO    ALDO    ALDO    ALDO    ALDO    ALDO

In particular, notice that field 'd' starts off wrong.
If I uncomment field 'e', or change one of them to an int, the problem goes
away.

At C, "ALDO" should be printed.
At B, "ODLA" should be printed.
At A, "ALDO" should be printed.

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


More information about the Digitalmars-d-bugs mailing list