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 ***