Thread overview
[Issue 24242] forward inside templates with -dip1000 causes memory corruption
Nov 13, 2023
Jan Jurzitza
Nov 13, 2023
Richard Cattermole
Nov 13, 2023
kinke
Nov 13, 2023
kinke
November 13, 2023
https://issues.dlang.org/show_bug.cgi?id=24242

--- Comment #1 from Jan Jurzitza <d.bugs@webfreak.org> ---
discovered bug conditions:
- the variable holding data MUST be created in a separate function, creating it
inline, e.g. in the `main` here, doesn't trigger the memory corruption
- the struct MUST be templated for this bug to occur (otherwise it works as
expected)

--
November 13, 2023
https://issues.dlang.org/show_bug.cgi?id=24242

Richard Cattermole <alphaglosined@gmail.com> changed:

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

--- Comment #2 from Richard Cattermole <alphaglosined@gmail.com> ---
Swapping forward for move, stops the bug.

Removing forward altogether also stops it.

Going through the alias sequence inside of forward appears to prevent the compiler from being able to see that the function parameter value is used, and therefore can go on the stack.

--
November 13, 2023
https://issues.dlang.org/show_bug.cgi?id=24242

kinke <kinke@gmx.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kinke@gmx.net

--- Comment #3 from kinke <kinke@gmx.net> ---
The problem appears to be that the compiler wrongly infers the `ulong[] value` ctor param as being `scope` (if the struct/ctor is templated). That then enables a (frontend) optimization, passing the array literal on the stack.

--
November 13, 2023
https://issues.dlang.org/show_bug.cgi?id=24242

--- Comment #4 from kinke <kinke@gmx.net> ---
(In reply to kinke from comment #3)
> passing the array literal on the stack

Well, allocating the array literal on the caller's stack and passing a slice to it.

--
August 21
https://issues.dlang.org/show_bug.cgi?id=24242

Sebastiaan Koppe <mail@skoppe.eu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mail@skoppe.eu

--- Comment #5 from Sebastiaan Koppe <mail@skoppe.eu> ---
Still present with dmd-2.109.1

--