Bug 17370 – [scope] Escaping scope pointers possible via struct GC allocation

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2017-05-05T08:33:00Z
Last change time
2017-10-16T09:57:27Z
Keywords
safe
Assigned to
No Owner
Creator
Mathias Lang

Comments

Comment #0 by mathias.lang — 2017-05-05T08:33:00Z
The following compiles and runs with 2.074.0 and v2.075.0-devel-5cfc8d982 (latest master): ``` void main () @safe { int* ptr = fwd(); assert(ptr !is null); } int* fwd () @safe { int i; return new Struct(&i).oops; // Leaving out `new` correctly detects escaping } struct Struct { int* oops; } ```
Comment #1 by petar.p.kirov — 2017-08-22T14:40:13Z
The issue is with only with the auto generated constructor. If you write one yourself, you get: void main () @safe { int* ptr = fwd(); assert(ptr !is null); } int* fwd () @safe { int i; return new Struct(&i).oops; } struct Struct { int* oops; this(int* p) @safe { oops = p; } } scope_bug17370.d(10): Error: reference to local variable i assigned to non-scope parameter p calling scope_bug17370.Struct.this
Comment #2 by bugzilla — 2017-08-25T20:11:40Z
Note: compile with -dip1000 to repro the problem.
Comment #3 by bugzilla — 2017-08-25T21:29:01Z
Comment #4 by github-bugzilla — 2017-09-01T08:10:57Z
Commits pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/ae05c4c834ee9944f8fc0ed21a990335bcf36c81 fix Issue 17370 - [scope] Escaping scope pointers possible via struct GC allocation https://github.com/dlang/dmd/commit/59e801d060ee13705cbf3bf73e1b4bc8a12aa60d Merge pull request #7101 from WalterBright/fix17370 fix Issue 17370 - [scope] Escaping scope pointers possible via struct… merged-on-behalf-of: Martin Nowak <[email protected]>
Comment #5 by github-bugzilla — 2017-10-16T09:57:27Z
Commits pushed to stable at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/ae05c4c834ee9944f8fc0ed21a990335bcf36c81 fix Issue 17370 - [scope] Escaping scope pointers possible via struct GC allocation https://github.com/dlang/dmd/commit/59e801d060ee13705cbf3bf73e1b4bc8a12aa60d Merge pull request #7101 from WalterBright/fix17370