www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - optimization of struct argument

reply "shinichiro.h" <s31552 mail.ecc.u-tokyo.ac.jp> writes:
Hi,

When I compile the following code with no optimization, the code works
good. But when I compile with optimization, the code works strange.

<code>
struct S {
    ubyte a, b, c, d;
}

int hoge(S s) {
    printf("%x\n", s);
    return 0;
}

int main() {
    for (int i = 0; i < 1; i++) {
        S s;
        s.a = 1;
        s.b = 2;
        s.c = 3;
        s.d = 4;
        hoge(s);
    }
    return 0;
}
</code>

This bug occurs on Windows and Linux. You can reproduce this bug in
the following way:

 dmd d.d

 ./d

 dmd -O d.d

 ./d

Oct 29 2004
parent "Thomas Kuehne" <thomas-dloop kuehne.cn> writes:
added to dstress as:
svn://svn.kuehne.cn/dstress/run/struct_14.d
svn://svn.kuehne.cn/dstress/run/struct_15.d

Thomas

shinichiro.h schrieb:
 Hi,

 When I compile the following code with no optimization, the code works
 good. But when I compile with optimization, the code works strange.

 <code>
 struct S {
     ubyte a, b, c, d;
 }

 int hoge(S s) {
     printf("%x\n", s);
     return 0;
 }

 int main() {
     for (int i = 0; i < 1; i++) {
         S s;
         s.a = 1;
         s.b = 2;
         s.c = 3;
         s.d = 4;
         hoge(s);
     }
     return 0;
 }
 </code>

 This bug occurs on Windows and Linux. You can reproduce this bug in
 the following way:

 dmd d.d

 ./d

 dmd -O d.d

 ./d


Oct 31 2004