Bug 18980 – Typesafe variadic array functions cause memory corruption

Status
RESOLVED
Resolution
DUPLICATE
Severity
critical
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2018-06-13T23:40:45Z
Last change time
2018-06-14T20:41:48Z
Assigned to
No Owner
Creator
Justin

Attachments

IDFilenameSummaryContent-TypeSize
1703badness.dReproduction codetext/x-dsrc1342

Comments

Comment #0 by mrjnewt — 2018-06-13T23:40:45Z
Created attachment 1703 Reproduction code I've attached a simple D program that builds a complex JSONValue using several helper functions with signatures like JSONValue or(JSONValue[] conditions...) {} I've found that the resulting programs have (sometimes) subtle memory corruption issues. To replicate, download the attached D file and compile & run with: dmd -run badness.d dmd -O -inline -release -run badness.d The issue manifests with optimizations on AND off, although generally differently: sometimes with bad JSON output, other times with a memory allocation failure. My guess is that the arguments to these variadic array functions are being stack allocated and passing out of scope. If you put `.dup` on the two lines indicated in the source, the problem is resolved.
Comment #1 by ag0aep6g — 2018-06-14T20:41:48Z
(In reply to Justin from comment #0) > My guess is that the arguments to these variadic array functions are being > stack allocated and passing out of scope. Correct. This is a duplicate of issue 5212, which has been fixed but only if you compile with the -dip1000 compiler switch. "Fixed" means the compiler rejects the code. *** This issue has been marked as a duplicate of issue 5212 ***