Thread overview
[Issue 14639] Assigning init value to struct uses stack, causing segfault
Jun 06, 2015
naptime
May 10, 2017
Walter Bright
May 10, 2017
Walter Bright
May 10, 2017
Walter Bright
Mar 27, 2020
Walter Bright
Mar 27, 2020
Dlang Bot
Mar 28, 2020
Dlang Bot
June 06, 2015
https://issues.dlang.org/show_bug.cgi?id=14639

naptime <naptimeentertainment@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |naptimeentertainment@gmail.
                   |                            |com

--
May 10, 2017
https://issues.dlang.org/show_bug.cgi?id=14639

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla@digitalmars.com

--- Comment #1 from Walter Bright <bugzilla@digitalmars.com> ---
What's happening is the existence of the postblit, even though disabled, causes the compiler to do the assignment by calling opAssign, where the argument is passed by value. Passing by value means pushing it to the stack.

--
May 10, 2017
https://issues.dlang.org/show_bug.cgi?id=14639

--- Comment #2 from Walter Bright <bugzilla@digitalmars.com> ---
https://github.com/dlang/dmd/pull/6766

--
May 10, 2017
https://issues.dlang.org/show_bug.cgi?id=14639

--- Comment #3 from Walter Bright <bugzilla@digitalmars.com> ---
The code:

    biggy = Biggy.init;

gets rewritten to be:

    biggy = Biggy([0LU, ...]);

which is a construction. The postblit caused an opAssign() to be created, and the expression is further rewritten to:

    biggy.opAssign(Biggy([0LU, ...]));

which blows up the parameter stack because Biggy([0LU, ...]) is too big for it. The operation is not disabled because it gets constructed in place - a copy is not being made.

A possible compiler fix is to figure out that the generated opAssign is trivial and can be replaced with a bit copy. The code in opover.d:

                if (sd && !sd.hasIdentityAssign)
                {
                    /* This is bitwise struct assignment. */
                    return;
                }

can be modified to test for triviality of identity assign, and use a bitwise copy.

--
March 27, 2020
https://issues.dlang.org/show_bug.cgi?id=14639

--- Comment #4 from Walter Bright <bugzilla@digitalmars.com> ---
This:

    https://github.com/dlang/dmd/pull/10967

changes the

    biggy = Biggy.init;

implementation into a memset.

--
March 27, 2020
https://issues.dlang.org/show_bug.cgi?id=14639

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull

--- Comment #5 from Dlang Bot <dlang-bot@dlang.rocks> ---
@WalterBright updated dlang/dmd pull request #6766 "fix Issue 14639 - Assigning init value to struct uses stack, causing …" fixing this issue:

- fix Issue 14639 - Assigning init value to struct uses stack, causing segfault

https://github.com/dlang/dmd/pull/6766

--
March 28, 2020
https://issues.dlang.org/show_bug.cgi?id=14639

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #6 from Dlang Bot <dlang-bot@dlang.rocks> ---
dlang/dmd pull request #6766 "fix Issue 14639 - Assigning init value to struct uses stack, causing …" was merged into master:

- a0b0b5783bffd806a45870d71aaa29c3883e5d7e by Walter Bright:
  fix Issue 14639 - Assigning init value to struct uses stack, causing segfault

https://github.com/dlang/dmd/pull/6766

--