Bug 13902 – Compiler allows escaping the address of part of a local

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-12-27T23:36:00Z
Last change time
2015-02-18T03:42:19Z
Keywords
accepts-invalid, pull
Assigned to
nobody
Creator
andrei

Comments

Comment #0 by andrei — 2014-12-27T23:36:49Z
Currently the compiler disallows this: ref int fun() { int x; return x; // escape the address of a local } However, this goes unchecked: struct S { int x; } ref int fun() { S s; return s.x; // escape the address of part of a local } Direct member access is easy to check using the same logic, so I'm filing this as a bug. DIP25 addresses more sophisticated detection cases.
Comment #1 by andrei — 2014-12-27T23:41:23Z
One more simple case, equivalent in fact because statically-sized arrays behave like structs: ref int lun() { int a[42]; return a[5]; } This should also be disallowed directly.
Comment #2 by k.hara.pg — 2015-01-11T05:10:31Z
Comment #3 by k.hara.pg — 2015-01-11T05:44:21Z
*** Issue 4232 has been marked as a duplicate of this issue. ***
Comment #4 by k.hara.pg — 2015-01-11T05:55:14Z
*** Issue 4451 has been marked as a duplicate of this issue. ***
Comment #5 by k.hara.pg — 2015-01-11T06:06:23Z
*** Issue 9537 has been marked as a duplicate of this issue. ***
Comment #6 by github-bugzilla — 2015-01-11T19:50:37Z
Commits pushed to master at https://github.com/D-Programming-Language/druntime https://github.com/D-Programming-Language/druntime/commit/b526fbd89465cce8c2ab7bef84007438395effca Supplemental fix for issue 13902, don't return a slice to local static array. https://github.com/D-Programming-Language/druntime/commit/097bb6feccdfe48a79e06d9be23eb88864b57d54 Merge pull request #1094 from 9rnsr/fix13902 Supplemental fix for issue 13902, don't return a slice to local static array.
Comment #7 by github-bugzilla — 2015-01-11T23:43:34Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/dc6235bc932c5a829c9a69b276c93462917a8f09 fix Issue 13902 - Compiler allows escaping the address of part of a local To visualize the current scope behavior, I added fail_compilation/fail_scope.d. https://github.com/D-Programming-Language/dmd/commit/0829ec3913fa27f24a1a952be7fca012126aa959 Merge pull request #4277 from 9rnsr/fix13902 Issue 13902 - Compiler allows escaping the address of part of a local
Comment #8 by github-bugzilla — 2015-02-18T03:38:43Z
Comment #9 by github-bugzilla — 2015-02-18T03:42:19Z