Bug 17828 – [ICE] Internal error: ddmd/backend/cgcs.c 352 - CTFE appending to an array on a struct from a template

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2017-09-15T07:47:34Z
Last change time
2020-03-21T03:56:31Z
Keywords
accepts-invalid, ice, pull
Assigned to
No Owner
Creator
David Bennett
See also
https://issues.dlang.org/show_bug.cgi?id=20011

Comments

Comment #0 by davidbennett — 2017-09-15T07:47:34Z
I'm getting the following internal error: & el:0x28d9280 cnt=0 cs=0 & TY* 0x28d70e0 el:0x28d70e0 cnt=0 cs=0 const TYucent 0LL+0LL Internal error: ddmd/backend/cgcs.c 352 For this code: struct Content{ string[] parts; } void add_part_to_content(Content content, string s)(){ content.parts ~= "Part: "~s; } void main(){ enum Content content = {}; add_part_to_content!(content, "Header")(); } I'm new to D templates / CTFE so not sure if the code is valid. In ether case it probably shouldn't give an Internal error.
Comment #1 by b2.temp — 2017-09-15T08:37:17Z
reduced: --- struct Content{string[] parts;} void main(){ enum Content content = {}; content.parts ~= ""; } ---
Comment #2 by b2.temp — 2019-06-29T17:01:13Z
The root of the problem is a check not done during sema I believe, because the following works --- struct Content{ubyte parts;} void main(){ enum Content content = {}; content.parts = 2; } --- fixing this last example should prevent the ICE as well. BTW another evidence showing that it's a missing bit in the front end is that LDC2 crashes too (with the reduced test case of comment #2).
Comment #3 by b2.temp — 2019-06-29T18:03:04Z
The previous example is actually a new regression
Comment #4 by dlang-bot — 2019-06-30T14:00:27Z
@Basile-z updated dlang/dmd pull request #10115 "fix issue 20011, fix issue 17828 - crash or accept write operation on members of manifest constant structs" fixing this issue: - fix issue 20011, 17828 - crash or accept write operation on members of manifest constant structs https://github.com/dlang/dmd/pull/10115
Comment #5 by dlang-bot — 2019-07-07T08:14:35Z
dlang/dmd pull request #10115 "fix issue 20011, 17828 - crash or accept write operation on members of manifest constant structs" was merged into stable: - 44469ba0c915f2cc9f017f01a8a738219a130c51 by Basile Burg: fix issue 20011, 17828 - crash or accept write operation on members of manifest constant structs https://github.com/dlang/dmd/pull/10115