D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 8079 - [64 bit] Memory corruption on stack-allocated temporary static arrays
Summary: [64 bit] Memory corruption on stack-allocated temporary static arrays
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Linux
: P2 critical
Assignee: No Owner
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2012-05-10 12:00 UTC by hsteoh
Modified: 2012-09-05 02:05 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description hsteoh 2012-05-10 12:00:55 UTC
Code:
        import std.stdio;
        struct S {
                short[4] x;
                this(short[4] args...) {
                        x[] = args[];
                }
                bool opEquals(in S s) const {
                        for (auto i=0; i < 4; i++) {
                                if (this.x[i] != s.x[i])
                                        return false;
                        }
                        return true;
                }
        }
        void main() {
                assert(S(1,2,3,4) == S(1,2,3,4));
        }

Output: with dmd -m64, the assertion fails. Inserting writeln's show that the elements of s in opEquals() are garbage values. Trying to print out the entire array of this or s causes a segfault.

On dmd -m32, there is no problem.

Not sure if this is related to bug 5570.
Comment 1 hsteoh 2012-05-10 12:11:18 UTC
P.S. Changing the static array to int[4] for some reason makes the problem go away. Don't know how this is relevant, but might be useful to track down the bug in the compiler.
Comment 2 hsteoh 2012-05-22 11:13:49 UTC
Can no longer reproduce this bug in latest git dmd, may have been fixed?
Comment 3 Damian Ziemba 2012-09-05 02:05:26 UTC
Seems to work with DMD 2.060 (and trunk) both with m32 and m64

http://dpaste.dzfl.pl/c6857366

I think we can close this issue as for now although I am not sure what certain Commit fixed it.