Bug 8957 – Closure not recognized when passing type with post-blit as lazy parameter

Status
NEW
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-11-03T07:20:13Z
Last change time
2024-12-13T18:02:20Z
Keywords
wrong-code
Assigned to
No Owner
Creator
David Nadlinger
Moved to GitHub: dmd#18484 →

Comments

Comment #0 by code — 2012-11-03T07:20:13Z
This is a follow-up to the thread »Expression::apply, DeclarationExp and a possible nested context bug« on dmd-internals: http://forum.dlang.org/thread/CAP9J_HXG8mTtnojU9YwYuSGZp1NQCdY0+7oeHyoQ2WhNR-dAuw@mail.gmail.com The following test case shows that the problem I brought up there there also leads to wrong-code bugs in DMD (at least I hope it's still the original problem, I simply extended this from the minimal testcase linked in the thread): --- extern(C) void printf(const char*, ...); struct HasPostblit { this(this) {}; } struct Foo { HasPostblit hp; int i; } void print(Foo f) { printf("%x\n", f.i); } auto toDg(E)(lazy E e) { return { return e(); }; } auto getDg() { Foo a; a.i = 0x1; return toDg(print(a)); } void smashStack() { int[1024] dummy = 0xcafebabe; } void main() { auto d = getDg(); smashStack(); d(); } ---
Comment #1 by clugdbug — 2012-11-05T00:50:41Z
Quite likely to be related to at least one of the other closure bugs: bug 1841, bug 1759, bug 2148, bug 6141.
Comment #2 by code — 2012-11-11T13:59:18Z
@Don: For an analysis of why this happens and a minimal test case, see the linked dmd-internals thread (I'm fairly sure that it is correct, having spent quite some time tracking down the issue in LDC). As to whether this is related to the other bugs, I'm not sure OTOH if an intermediary DeclarationExp is also generated for them.
Comment #3 by ibuclaw — 2013-04-06T11:25:53Z
Partial fix. https://github.com/D-Programming-Language/dmd/pull/1854 What changes is that 'Foo a' is now added to closureVars for the function getDg().
Comment #4 by bugzilla — 2013-04-06T13:04:05Z
(In reply to comment #3) > Partial fix. What is left undone?
Comment #5 by github-bugzilla — 2013-04-06T13:05:09Z
Commit pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/bea22e33b11ac8efd07081f43fac1d54d2a9aab2 Merge pull request #1854 from ibuclaw/issue8957 Check declaration initializer expressions for nested refs.
Comment #6 by ibuclaw — 2013-04-06T16:14:57Z
(In reply to comment #4) > (In reply to comment #3) > > Partial fix. > > What is left undone? Detection in FuncDeclaration:: needsClosure.
Comment #7 by robert.schadek — 2024-12-13T18:02:20Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18484 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB