CTFE Status

Patrick Schluter via Digitalmars-d digitalmars-d at puremagic.com
Thu Jan 26 03:59:48 PST 2017


On Thursday, 26 January 2017 at 07:27:13 UTC, Stefan Koch wrote:
> On Wednesday, 25 January 2017 at 12:36:02 UTC, Stefan Koch 
> wrote:
>> newCTFE is green now on all platforms!
>
> I just found an interesting bug just now.
> The following code would cause newCTFE to segfault.
>
> char* initPtr()
> {
>     return cast(char*) size_t.max;
> }
>
> static assert(cast(size_t)initPtr() == size_t.max);
>
> Because it would try to return the char-value at heap-address 
> size_t.max;
> newCTFE allocates a 16MB heap by default and therefore the 
> address was hopelessly out-of-bounds.
>
> The reason this was not detected before is because:
>   `cast(char*) size_t.max;`
> does not actually produce a cast expression.
> But rather an IntegerLiteral with the type char*.
>
> After dealing with dmd for 7 months, I could figure out this 
> bug in a day.
> If I had run into this earlier I would have been stuck for 
> weeks :)

I do not understand why it should dereference the pointer? Do you 
mean that the bug was that newCTFE dereferenced but it shouldn't 
or that oldCTFE didn't dereference but it should have?


More information about the Digitalmars-d mailing list