Bug 23813 – DIP1000 can introduce memory corruption in @safe function with typesafe variadics

Status
REOPENED
Severity
critical
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2023-03-28T15:01:49Z
Last change time
2024-12-13T19:28:03Z
Assigned to
No Owner
Creator
kinke
Moved to GitHub: dmd#20253 →

Comments

Comment #0 by kinke — 2023-03-28T15:01:49Z
With DMD v2.102: ``` auto foo(scope int[] i...) @safe { return () { import core.stdc.stdio; foreach (j; i) printf("%d\n", j); }; } auto bar() @safe { return foo([1, 2, 3, 4, 5, 6]); } void main() { auto dg = bar(); dg(); } ``` This works 'fine' without `-dip1000`. With DIP1000, it prints garbage (array literal allocated on the stack then). It ultimately boils down to the `scope` violation in `foo` not being detected. Related to https://issues.dlang.org/show_bug.cgi?id=23440.
Comment #1 by kinke — 2023-03-28T15:07:40Z
Oh, the `scope` annotation isn't required, bug happens without `scope` too - probably because of https://github.com/dlang/dmd/pull/14324 ('typesafe variadic parameters should automatically be scope with DIP1000').
Comment #2 by razvan.nitu1305 — 2023-03-29T07:54:19Z
This seems to be an exact dupe of 23440. *** This issue has been marked as a duplicate of issue 23440 ***
Comment #3 by kinke — 2023-03-29T11:48:49Z
It's not a duplicate, otherwise I wouldn't have filed this, with the cross-link. The underlying cause is most likely the same (undetected `scope` violation), but this specific issue here is about DIP1000 making things worse instead of better.
Comment #4 by robert.schadek — 2024-12-13T19:28:03Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20253 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB