[Issue 14220] Bad codegen for optimized std.conv.text in combination with concatenation

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Fri Feb 27 05:25:05 PST 2015


https://issues.dlang.org/show_bug.cgi?id=14220

--- Comment #3 from Kenji Hara <k.hara.pg at gmail.com> ---
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.

--


More information about the Digitalmars-d-bugs mailing list