Bug 9982 – ICE on CTFE for pointer dereference

Status
RESOLVED
Resolution
FIXED
Severity
critical
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-04-23T03:23:00Z
Last change time
2015-06-09T05:11:49Z
Keywords
CTFE, ice, wrong-code
Assigned to
nobody
Creator
monarchdodra

Comments

Comment #0 by monarchdodra — 2013-04-23T03:23:13Z
Assertion failure: 'dest->op == TOKstructliteral || dest->op == TOKarrayliteral || dest->op == TOKstring' on line 1604 in file 'ctfeexpr.c' and Error: cannot dereference invalid pointer *chunk //---------------- static struct S { } struct SS { S s2; //[1] this(S s1) { //S s2; //[2] emplace(&s2, s1); } } void emplace(S* chunk, S arg) { emplacePostblitter(*chunk, arg); //[3] *chunk = arg; //[4] } private void emplacePostblitter(ref S chunk, S arg) { chunk = arg; } enum s = S(); enum p = SS(s); //---------------- Getting two different errors: [3] : //Assertion failure: 'dest->op == TOKstructliteral || dest->op == TOKarrayliteral || dest->op == TOKstring' on line 1604 in file 'ctfeexpr.c' If we comment [3], then it is [4] that errors: [4] Error: cannot dereference invalid pointer *chunk Interesting enough, if we move line [1] to line [2], then everything works fine.
Comment #1 by wazar.leollone — 2013-04-23T07:03:08Z
I've tried to simplify this bug case. My resolution: error in operation of taking address of struct member and dereference it. We must ask Don about this. struct Foo(T) { T a; this(T arg) { T* p = &a; *p = arg; } this(T arg, int) { T* p = &a; setRef(*p, arg); } static void setRef(ref T p, T v) { p = v; } } auto ct1 = Foo!int(99); //compiled, but doesn't set this.a to 99 auto ct2 = Foo!int(99, 0); //compiled, but doesn't set this.a to 99 //try with struct struct Bar { int b; } auto ct1_2 = Foo!Bar(Bar(99)); //Error auto ct2_2 = Foo!Bar(Bar(99), 0); //ICE void main() { assert(ct1.a != 99); assert(ct2.a != 99); }
Comment #2 by clugdbug — 2013-07-09T02:00:27Z
This is a critical bug. Assignment via a pointer to a struct member does not work! struct Bug9982 { int a; } int test9982() { Bug9982 x; int *q = &x.a; *q = 99; assert(x.a == 99); return 1; } static assert(test9982());
Comment #3 by github-bugzilla — 2013-08-26T23:56:25Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/72b160b53662feeb927175260f9e1b165b86009a Issue 9982 case(b) wrong code for dotvar pointer assign The existing code was complicated and just plain wrong. https://github.com/D-Programming-Language/dmd/commit/16c3d57ee460f368337bbd3f2dea39a1ff6e1903 Fix issue 9982 ICE on CTFE for pointer dereference CTFE assignments can resolve to a StructLiteral inplace assign.
Comment #4 by bugzilla — 2013-08-26T23:56:53Z
Fixed for D2.
Comment #5 by github-bugzilla — 2013-09-13T10:45:53Z
Commit pushed to dmd-1.x at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/0e7de354e055464634565f22bc764c9695b0475a Issue 9982 case(b) wrong code for dotvar pointer assign The existing code was complicated and just plain wrong.