Bug 14220 – Bad codegen for optimized std.conv.text in combination with concatenation

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Windows
Creation time
2015-02-24T13:11:00Z
Last change time
2015-06-17T22:25:14Z
Keywords
wrong-code
Assigned to
nobody
Creator
r.sagitario

Comments

Comment #0 by r.sagitario — 2015-02-24T13:11:25Z
module test; import std.conv; void main() { string s = "err: " ~ text(14); } Compiling this on win64 with: dmd -g -m64 -release -inline -O test.d generates a crashing program. The error seems to disappear if one of -release ,-inline and -O is removed. It also does not happen without the concatenation.
Comment #1 by r.sagitario — 2015-02-24T13:13:58Z
According to git-bisect this has been introduced with https://github.com/D-Programming-Language/dmd/pull/4408, so it is not in dmd 2.067 beta2.
Comment #2 by ketmar — 2015-02-25T01:07:15Z
just in case: it's ok with GNU/Linux, x86. so this seems to be 64-bit issue.
Comment #3 by k.hara.pg — 2015-02-27T13:25:05Z
Reduced test case: extern(C) int printf(const char*, ...); void main() { auto a = toString(14); printf("a.ptr = %p, a.length = %d\n", a.ptr, cast(int)a.length); return; } auto toString(int value) { uint mValue = value; char[int.sizeof * 3] buffer = void; size_t index = buffer.length; do { uint div = cast(int)(mValue / 10); char mod = mValue % 10 + '0'; buffer[--index] = mod; // Line 22 mValue = div; } while (mValue); //printf("buffer.ptr = %p, index = %d\n", buffer.ptr, cast(int)index); return dup(buffer[index .. $]); } char[] dup(char[] a) { //printf("a.ptr = %p, a.length = %d\n", a.ptr, cast(int)a.length); a[0] = 1; // segfault return a; } The wrong-code bug is introduced by the change: https://github.com/D-Programming-Language/dmd/pull/4415 However, the PR 4415 only affects to line 22. so I think the root issue would exist in dmd backend optimizer.
Comment #4 by bugzilla — 2015-02-28T22:24:37Z
I'll check it out.
Comment #5 by bugzilla — 2015-02-28T22:32:03Z
Can repro on Win64 with the switches: -m64 -O -release
Comment #6 by bugzilla — 2015-03-01T09:23:04Z
Comment #7 by github-bugzilla — 2015-03-01T10:08:57Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/9295312a23e85dcd1b026cf3b25feb0330379185 fix Issue 14220 - Bad codegen for optimized std.conv.text in combination with concatenation https://github.com/D-Programming-Language/dmd/commit/e43136308f7eb035d046a99a46ffbdaf880413b7 Merge pull request #4451 from WalterBright/fix14220 fix Issue 14220 - Bad codegen for optimized std.conv.text in combination...
Comment #8 by github-bugzilla — 2015-03-28T19:39:12Z
Commit pushed to stable at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/f37749d65561cd019ae9b54ed8ee3474a54a6a6e Merge pull request #4451 from WalterBright/fix14220 fix Issue 14220 - Bad codegen for optimized std.conv.text in combination...
Comment #9 by github-bugzilla — 2015-04-11T12:25:17Z
Comment #10 by github-bugzilla — 2015-06-17T21:01:32Z
Commits pushed to stable at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/9295312a23e85dcd1b026cf3b25feb0330379185 fix Issue 14220 - Bad codegen for optimized std.conv.text in combination with concatenation https://github.com/D-Programming-Language/dmd/commit/e43136308f7eb035d046a99a46ffbdaf880413b7 Merge pull request #4451 from WalterBright/fix14220