Thread overview
[Issue 22215] returning expired stack pointers in @system code allowed by spec, not by implementation
Aug 16, 2021
Dennis
Aug 25, 2021
Ate Eskola
Aug 25, 2021
Dennis
Feb 17, 2022
Walter Bright
Feb 17, 2022
Walter Bright
Mar 07, 2022
Dlang Bot
Mar 08, 2022
Dlang Bot
August 16, 2021
https://issues.dlang.org/show_bug.cgi?id=22215

Dennis <dkorpel@live.nl> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dkorpel@live.nl
           Hardware|x86                         |All
            Summary|[dip1000] scope analysis    |returning expired stack
                   |does not respect @system or |pointers in @system code
                   |@trusted                    |allowed by spec, not by
                   |                            |implementation
           Severity|major                       |normal

--- Comment #1 from Dennis <dkorpel@live.nl> ---
It doesn't compile without -dip1000 either, the error predates it.

> this workaround should not be required.

Intentionally returning an expired stack pointer should be a very rare occurrence, I think a workaround is warranted. However, the spec says:

> @system functions may perform any operation legal from the perspective of the language including inherently memory unsafe operations like returning pointers to expired stackframes

https://dlang.org/spec/memory-safe-d.html

So at least one has to change: the implementation, or the spec.

--
August 25, 2021
https://issues.dlang.org/show_bug.cgi?id=22215

--- Comment #2 from Ate Eskola <Ajieskola@gmail.com> ---
There appears to be two bugs, one in vanilla DMD and one with -dip1000.

As Dennis said, my initial example fails to compile regardless of the compiler switches used. But there is a watered-down version of my workaround:

```d
int* f()
{ int x = 42;
  auto wannaBePointer = &x;
  return wannaBePointer;
}
```

This one compiles with vanilla DMD, but the -dip1000 bug prevents compiling it with the said flag.

The full workaround in the initial example still compiles with the flag too.

--
August 25, 2021
https://issues.dlang.org/show_bug.cgi?id=22215

--- Comment #3 from Dennis <dkorpel@live.nl> ---
(In reply to Ate Eskola from comment #2)
> There appears to be two bugs, one in vanilla DMD and one with -dip1000.

That's right, the latter one is https://issues.dlang.org/show_bug.cgi?id=19873

--
February 17, 2022
https://issues.dlang.org/show_bug.cgi?id=22215

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |safe
                 CC|                            |bugzilla@digitalmars.com
           Severity|normal                      |minor

--- Comment #4 from Walter Bright <bugzilla@digitalmars.com> ---
We shouldn't fix this. It's such an easy mistake to make, with terrible consequences. Allowing the wannaBePointer workaround is good enough.

Downgraded this to 'minor'.

Probably an adjustment to the spec would be better.

--
February 17, 2022
https://issues.dlang.org/show_bug.cgi?id=22215

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|dmd                         |dlang.org

--- Comment #5 from Walter Bright <bugzilla@digitalmars.com> ---
Changed it to a spec bug.

--
March 07, 2022
https://issues.dlang.org/show_bug.cgi?id=22215

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

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

--- Comment #6 from Dlang Bot <dlang-bot@dlang.rocks> ---
@dkorpel created dlang/dlang.org pull request #3246 "Fix issue 22215 - returning expired stack pointers in `@system` code …" fixing this issue:

- Fix issue 22215 - returning expired stack pointers in `@system` code allowed by spec, not by implementation

https://github.com/dlang/dlang.org/pull/3246

--
March 08, 2022
https://issues.dlang.org/show_bug.cgi?id=22215

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

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

--- Comment #7 from Dlang Bot <dlang-bot@dlang.rocks> ---
dlang/dlang.org pull request #3246 "Fix issue 22215 - returning expired stack pointers in `@system` code …" was merged into master:

- 0e09baaf7bb31a3eaea6fb28359d11cc8a20276f by Dennis Korpel:
  Fix issue 22215 - returning expired stack pointers in `@system` code allowed
by spec, not by implementation

https://github.com/dlang/dlang.org/pull/3246

--