Bug 23181 – [REG 2.099] AssertError@src/dmd/e2ir.d(6094): Trying reference _d_arraysetctor

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-06-13T14:46:37Z
Last change time
2022-07-09T16:32:07Z
Keywords
pull
Assigned to
No Owner
Creator
Iain Buclaw

Comments

Comment #0 by ibuclaw — 2022-06-13T14:46:37Z
--- void main() { struct HasDtor { int i; ~this() { } } HasDtor[4] arr = HasDtor(4); } --- core.exception.AssertError@src/dmd/e2ir.d(6094): Trying reference _d_arraysetctor, this should not happen! ---------------- ??:? _d_assert_msg [0x556350ef01fc] src/dmd/e2ir.d:6094 _Z8setArrayP10ExpressionP4elemS2_P4TypeS2_P7IRStatei [0x556350da4236] src/dmd/e2ir.d:2196 dmd.backend.el.elem* dmd.e2ir.toElem(dmd.expression.Expression, dmd.toir.IRState*).visitAssign(dmd.expression.AssignExp) [0x556350d995e4] src/dmd/e2ir.d:4036 _Z6toElemP10ExpressionP7IRState [0x556350d93576] src/dmd/e2ir.d:4137 _Z14Dsymbol_toElemP7DsymbolP7IRState [0x556350d9f045] src/dmd/e2ir.d:790 dmd.backend.el.elem* dmd.e2ir.toElem(dmd.expression.Expression, dmd.toir.IRState*).visitDeclaration(dmd.expression.DeclarationExp) [0x556350d94afc] src/dmd/e2ir.d:4078 _Z6toElemP10ExpressionP7IRState [0x556350d939a0] src/dmd/e2ir.d:411 _Z10toElemDtorP10ExpressionP7IRState [0x556350d93018] src/dmd/s2ir.d:768 _ZN11S2irVisitor5visitEP12ExpStatement [0x556350dbe54c] src/dmd/statement.d:485 _ZN12ExpStatement6acceptEP7Visitor [0x556350d4fe4d] src/dmd/s2ir.d:1538 _ZN11S2irVisitor14Statement_toIREP9StatementP7IRStateP9StmtStateI5blockE [0x556350dc069f] src/dmd/s2ir.d:787 _ZN11S2irVisitor5visitEP17CompoundStatement [0x556350dbe607] src/dmd/statement.d:628 _ZN17CompoundStatement6acceptEP7Visitor [0x556350d50371] src/dmd/s2ir.d:1538 _ZN11S2irVisitor14Statement_toIREP9StatementP7IRStateP9StmtStateI5blockE [0x556350dc069f] src/dmd/s2ir.d:787 _ZN11S2irVisitor5visitEP17CompoundStatement [0x556350dbe607] src/dmd/statement.d:628 _ZN17CompoundStatement6acceptEP7Visitor [0x556350d50371] src/dmd/s2ir.d:1558 _Z14Statement_toIRP9StatementP7IRState [0x556350dc079b] src/dmd/glue.d:1102 _Z25FuncDeclaration_toObjFileP15FuncDeclarationb [0x556350db5902] src/dmd/toobj.d:315 _ZN9toObjFile9ToObjFile5visitEP15FuncDeclaration [0x556350dcdee5] src/dmd/func.d:2920 _ZN15FuncDeclaration6acceptEP7Visitor [0x556350cdae4d] src/dmd/toobj.d:1022 _Z9toObjFileP7Dsymbolb [0x556350dcde4c] src/dmd/glue.d:523 _Z10genObjFileP6Moduleb [0x556350db3e9b] src/dmd/glue.d:121 void dmd.glue.generateCodeAndWrite(dmd.dmodule.Module[], const(char)*[], const(char)[], const(char)[], bool, bool, bool, bool, bool) [0x556350db26ea] src/dmd/mars.d:577 int dmd.mars.tryMain(ulong, const(char)**, ref dmd.globals.Param) [0x556350bc4c7a] src/dmd/mars.d:961 _Dmain [0x556350bc61f9]
Comment #1 by ibuclaw — 2022-06-13T15:23:59Z
In the release binaries of dmd, you can see that there is a run-time regression as well. --- void main() { struct hasDtor { import core.stdc.stdio; int count; ~this() { printf("dtor(%d)\n", count); } } hasDtor[4] arr4 = hasDtor(4); } --- dtor(1) dtor(37) dtor(0) dtor(0) dtor(4) dtor(4) dtor(4) dtor(4) --- Because the codegen is calling _d_arraysetassign, the destructor is being ran on the uninitialized array.
Comment #2 by ibuclaw — 2022-06-13T15:39:27Z
The correct behaviour would be: --- void main() { int count; { struct hasDtor { ~this() { ++count; } } hasDtor[4] arr4 = hasDtor(); assert(count == 1); } assert(count == 5); } ---
Comment #3 by dlang-bot — 2022-06-13T18:11:07Z
@ibuclaw created dlang/dmd pull request #14210 "fix Issue 23181 - [REG 2.099] AssertError@src/dmd/e2ir.d(6094): Trying reference _d_arraysetctor" fixing this issue: - fix Issue 23181 - [REG 2.099] AssertError@src/dmd/e2ir.d(6094): Trying reference _d_arraysetctor https://github.com/dlang/dmd/pull/14210
Comment #4 by dlang-bot — 2022-06-13T19:55:18Z
dlang/dmd pull request #14210 "fix Issue 23181 - [REG 2.099] AssertError@src/dmd/e2ir.d(6094): Trying reference _d_arraysetctor" was merged into stable: - 807771fc7326a7de46ee3c5407e7946776abd509 by Iain Buclaw: fix Issue 23181 - [REG 2.099] AssertError@src/dmd/e2ir.d(6094): Trying reference _d_arraysetctor https://github.com/dlang/dmd/pull/14210
Comment #5 by dlang-bot — 2022-07-09T16:32:07Z
dlang/dmd pull request #14280 "merge stable" was merged into master: - 84ee8c96ec85782ef33e6ee25aaa7005bf477580 by Iain Buclaw: fix Issue 23181 - [REG 2.099] AssertError@src/dmd/e2ir.d(6094): Trying reference _d_arraysetctor https://github.com/dlang/dmd/pull/14280