[Issue 9130] Wrong codegen for compile time constructed struct

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Feb 4 00:55:37 PST 2013


http://d.puremagic.com/issues/show_bug.cgi?id=9130



--- Comment #3 from Maxim Fomin <maxim at maxim-fomin.ru> 2013-02-04 00:55:34 PST ---
Reduced:

class S { void bar() { } }

import core.stdc.stdio : printf;

struct Function
{
    int[] ai = [1,2,3];
}

@property void meta(alias m)()
{
    static Function md;
    printf("length = %d\n", md.ai.length);
    printf("ptr = %p\n", md.ai.ptr);
    md.ai[0] = 0;
}

void main()
{
    meta!(__traits(getOverloads, S, "bar")[0]);
    meta!(S.bar);
}

Strangely dmd generates two functions and places two md objects in thread local
storage (at least it reports do so). It seems that whatever __traits returns,
is treated differently from S.bar. 

This leads to following problem. When above code is run, it outputs:

length = 3
ptr = 0xc6c540
Segmentation fault

So, thread local md object seems to be allocated, but array pointer is
corrupted. If either of meta invocations is commented out, the code prints

length = 3
ptr = 0x636298

So, pointer is valid. Ironically 0x636298 * 2 meta functions = 0xC6C530

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list