Bug 24337 – Segfault when printing an int[] cast from a string literal

Status
RESOLVED
Resolution
FIXED
Severity
critical
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2024-01-12T12:12:01Z
Last change time
2024-11-16T23:27:08Z
Keywords
ice-on-valid-code, pull
Assigned to
No Owner
Creator
Dennis

Comments

Comment #0 by dkorpel — 2024-01-12T12:12:01Z
This code segfaults dmd: ```D immutable ushort[] z = cast(immutable ushort[]) "ab"w; pragma(msg, z); ``` The problem is in expressionsem.d: ``` StringExp toUTF8(StringExp se, Scope* sc) { if (se.sz != 1) { // Convert to UTF-8 string se.committed = false; Expression e = castTo(se, sc, Type.tchar.arrayOf()); e = e.optimize(WANTvalue); auto result = e.isStringExp(); assert(result.sz == 1); return result; } return se; } ``` This function assumes casting a StringExp to char[] will always succeed, which is false in the above case.
Comment #1 by dlang-bot — 2024-07-19T15:20:35Z
@dkorpel created dlang/dmd pull request #16729 "Fix bugzilla 24337 - Segfault when printing an int[] cast from a stri…" fixing this issue: - Fix bugzilla 24337 - Segfault when printing an int[] cast from a string literal https://github.com/dlang/dmd/pull/16729
Comment #2 by dlang-bot — 2024-07-22T08:00:43Z
dlang/dmd pull request #16729 "Fix bugzilla 24337 - Segfault when printing an int[] cast from a stri…" was merged into stable: - bb41c7e0e2264d2bcdcc63d6cfc2f089e5f3f1b8 by Dennis Korpel: Fix bugzilla 24337 - Segfault when printing an int[] cast from a string https://github.com/dlang/dmd/pull/16729
Comment #3 by dlang-bot — 2024-10-07T09:00:23Z
dlang/dmd pull request #16967 "Rebase stable6" was merged into master: - 7e42effe7a5657d4443a7ea00e3509b889fd52b6 by Dennis: Fix bugzilla 24337 - Segfault when printing an int[] cast from a string (#16729) https://github.com/dlang/dmd/pull/16967
Comment #4 by dlang-bot — 2024-11-16T23:27:08Z
dlang/dmd pull request #17069 "Merge stable" was merged into master: - cf618a659c92a0a6fcbc9079af29c72a8af27b76 by Dennis: Fix bugzilla 24337 - Segfault when printing an int[] cast from a string (#16729) https://github.com/dlang/dmd/pull/17069