Bug 14024 – [CTFE] unstable postblit/destructor call order on static array assignment

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-01-22T04:10:00Z
Last change time
2015-02-18T03:38:52Z
Keywords
CTFE, pull
Assigned to
nobody
Creator
k.hara.pg

Comments

Comment #0 by k.hara.pg — 2015-01-22T04:10:39Z
I found this unstable runtime behavior while fixing other CTFE issues. Test case: import core.stdc.stdio; int test14022() { string op; struct S { char x = 'x'; this(this) { op ~= x - ('a'-'A'); } // upper case ~this() { op ~= x; } // lower case } struct T { S[2] member; } S[2] makeSA() { return typeof(return).init; } version(A) { S[2] sa = [S('a'), S('b')]; S[2] sb = [S('x'), S('y')]; } else { S[2] sb = [S('x'), S('y')]; S[2] sa = [S('a'), S('b')]; } op = null; sa = sb; printf("op = %.*s\n", op.length, op.ptr); return 1; } void main() { test14022(); } The program output will be switched: op = XaYb and: op = YbXa Depending on the compiler switch -version=A. (To be precise, it depends on the stack address of sa and sb.) On static array assignment `sa = sb;`, the order of postblit/destructor calls should be normal if lhs and rhs have distinct memories.
Comment #1 by k.hara.pg — 2015-01-22T12:21:33Z
Comment #2 by github-bugzilla — 2015-01-22T23:46:41Z
Commits pushed to master at https://github.com/D-Programming-Language/druntime https://github.com/D-Programming-Language/druntime/commit/d478ee97b6fb6c8105e4435000569d3cd2a16196 fix Issue 14024 - unstable postblit/destructor call order on static array assignment https://github.com/D-Programming-Language/druntime/commit/1a0f8aac7a9cb6fa99c2c9b1fa651f5ebd01aaa2 Merge pull request #1115 from 9rnsr/fix14024 Issue 14024 - unstable postblit/destructor call order on static array assignment
Comment #3 by k.hara.pg — 2015-01-24T18:36:23Z
Reopen to fix CTFE behavior.
Comment #4 by k.hara.pg — 2015-01-24T20:55:36Z
Comment #5 by github-bugzilla — 2015-01-26T04:51:43Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/d853be97b1a84d04361ff23e014364bf32b7c7b8 fix Issue 14024 - [CTFE] unstable postblit/destructor call order on static array assignment https://github.com/D-Programming-Language/dmd/commit/0fd5758941b0055080468bf6d1a55ea59dbe834b Merge pull request #4332 from 9rnsr/fix14024 Issue 14024 - [CTFE] unstable postblit/destructor call order on static array assignment
Comment #6 by github-bugzilla — 2015-02-18T03:38:52Z