Bug 14686 – Postblit isn't sometimes called on concatenation

Status
RESOLVED
Resolution
FIXED
Severity
critical
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-06-12T04:22:00Z
Last change time
2016-03-19T20:21:49Z
Keywords
CTFE, pull, wrong-code
Assigned to
nobody
Creator
k.hara.pg

Comments

Comment #0 by k.hara.pg — 2015-06-12T04:22:57Z
Test case: extern(C) int printf(const char*, ...); int test() { string r; struct S { int n; this(this) { if (!__ctfe) printf("copy n = %d\n", n); r ~= cast(char)('0' + n); } } S s1 = S(1); S s2 = S(2); S[] a1 = [S(1)]; if (!__ctfe) printf("0--\n"); S[2] sa1 = [s1, s2]; if (!__ctfe) printf("1-- %.*s\n", r.length, r.ptr); assert(r == "12", r); // OK r = ""; S[] a2 = a1 ~ s2; // runtime concatenation if (!__ctfe) printf("2-- %.*s\n", r.length, r.ptr); //assert(r == "12", r); // NG only in CTFE r = ""; S[2] sa2a = [s1] ~ s2; if (!__ctfe) printf("3a-- %.*s\n", r.length, r.ptr); //assert(r == "12", r); // NG, s2 is not copied r = ""; S[2] sa2b = s2 ~ [s1]; if (!__ctfe) printf("3b-- %.*s\n", r.length, r.ptr); //assert(r == "21", r); // NG, s2 is not copied r = ""; S[3] sa3a = ([s1] ~ [s1]) ~ s2; if (!__ctfe) printf("4a-- %.*s\n", r.length, r.ptr); //assert(r == "112", r); // NG, s2 is not copied r = ""; S[3] sa3b = s2 ~ ([s1] ~ [s1]); if (!__ctfe) printf("4b-- %.*s\n", r.length, r.ptr); //assert(r == "211", r); // NG, s2 is not copied return 1; } static assert(test()); // CTFE test void main() { test(); } // runtime test Output: $ dmd -run test 0-- copy n = 1 copy n = 2 1-- 12 copy n = 1 copy n = 2 2-- 12 copy n = 1 3a-- 1 copy n = 1 3b-- 1 copy n = 1 copy n = 1 4a-- 11 copy n = 1 copy n = 1 4b-- 11
Comment #1 by k.hara.pg — 2015-06-12T12:09:54Z
Comment #2 by dlang-bugzilla — 2015-07-03T16:29:55Z
I just ran into this too - reduced a memory corruption bug for three days. This is a critical issue affecting the memory safety of reference-counted objects. I verified that the PR fixes my test case. Thanks!
Comment #3 by k.hara.pg — 2015-08-08T01:42:13Z
(In reply to Kenji Hara from comment #1) > https://github.com/D-Programming-Language/dmd/pull/4741 That PR also contains other changes. So I opened one more PR only for this bug. https://github.com/D-Programming-Language/dmd/pull/4869
Comment #4 by github-bugzilla — 2016-01-31T13:51:43Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/795a828fb8d4fff09530ba49c6124e2cf4ff939f fix Issue 14686 - Postblit isn't sometimes called on concatenation https://github.com/D-Programming-Language/dmd/commit/9b0ea6ea9b86ef032e0551cccae1358f08c695d8 Merge pull request #4869 from 9rnsr/fix14686 Issue 14686 - Postblit isn't sometimes called on concatenation
Comment #5 by github-bugzilla — 2016-03-19T20:21:49Z