Hi!

While trying to port LDC to PPC64 I ran into the following CTFE issue. This small program (reduced from std.conv.to!string(int)):

import core.stdc.stdio : printf;

string toStr()
{
    char x[];
    x.length = 16;
    x[0..3] = "666";
    x.length = 3;
    return cast(string) x;
}

string gencode()
{
    return "int x = " ~ toStr ~ ";";
}

void main()
{
    mixin(gencode());
    printf("Value of gencode: |%s|\n", gencode().ptr);
}

produces the error:
bug2.d(19): Error: expression expected, not 'EOF'
bug2.d(19): Error: semicolon expected, not 'EOF'
(the mixin statement is in line 19)

From the log I conclude that it must have something to do with the split range and array join:

bug2.d(8) VarExp::interpret() x
REF ASSIGN: x=['6', '6', '6']
ARRAY LITERAL type=char[] 0x10011b59040:
 void
 void
 void
bug2.d(9) ReturnStatement::interpret(cast(string)x)
bug2.d(9) CastExp::interpret() cast(string)x
bug2.d(9) VarExp::interpret() x
RETURN bug2.d(9)
ARRAY LITERAL type=char[] 0x10011b59040:
 void
 void
 void
bug2.d(4) -CompoundStatement::interpret() 0x10011b59040
 -CompoundStatement::interpret() 0x10011b59040
bug2.d(14) StringExp::interpret() ";"
RETURN bug2.d(14)
STRING "int x = \x00\x00\x00;" 0x10011b593c0
 -CompoundStatement::interpret() 0x10011b593e0

Needless to say that it works on x86 with dmd (2.061) and on x86_64 with ldc2 (based on 2.060). The error does not show up if I (a) replace the mixin statement with mixin("int x = " ~ toStr ~ ";") or (b) do a return "666" in toStr().

Does anybody have a hint how I can reduce this further? E.g. is there a way to view the content of the array?

Thanks in advance.

Kai


_______________________________________________
dmd-internals mailing list
[email protected]
http://lists.puremagic.com/mailman/listinfo/dmd-internals

Reply via email to