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.
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