Thread overview
[Issue 7732] New: CTFE bug causes if(ptr !is null) to pass when ptr==null
[Issue 7732] [CTFE] wrong code for a struct called AssociativeArray
Mar 20, 2012
Don
March 19, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7732

           Summary: CTFE bug causes if(ptr !is null) to pass when
                    ptr==null
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: critical
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: hsteoh@quickfur.ath.cx


--- Comment #0 from hsteoh@quickfur.ath.cx 2012-03-19 07:55:54 PDT ---
Something is BADLY broken with CTFE:

struct AssociativeArray
{
    int *impl;
    int f()
    {
        if (impl !is null)
            auto x = *impl; // this is line 7
        return 1;
    }
}
void main() {
    int test()
    {
        AssociativeArray aa;
        return aa.f;
    }
    enum str = test();
}


This is not a fully minimized test case, but I've tried my best to reduce it as much as possible. With the latest dmd from git, this gives:

test.d(7): Error: dereference of invalid pointer 'AssociativeArray(null)'
test.d(15):        called from here: aa.f()
test.d(17):        called from here: test()


This is a VERY serious bug because apparently the condition (impl !is null) actually passes, even though impl is null!

This appears to be related to the current AssociativeArray magic (renaming the struct in the above code makes the bug go away).

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 20, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7732


Don <clugdbug@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code
                 CC|                            |clugdbug@yahoo.com.au
            Summary|CTFE bug causes if(ptr !is  |[CTFE] wrong code for a
                   |null) to pass when          |struct called
                   |ptr==null                   |AssociativeArray


--- Comment #1 from Don <clugdbug@yahoo.com.au> 2012-03-19 23:31:21 PDT ---
This is very obscure, I don't think anybody else will ever encounter this. But it's an easy fix.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 20, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7732



--- Comment #2 from github-bugzilla@puremagic.com 2012-03-20 13:39:28 PDT ---
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/5a090eceffae47a3b64f0d64010bec948bdb842a Fix issue 7732 [CTFE] wrong code for a struct called AssociativeArray

https://github.com/D-Programming-Language/dmd/commit/85750ef0108f9493e30bcff7348439e9d17a4736 Merge pull request #818 from donc/assoc7732

Fix issue 7732 [CTFE] wrong code for a struct called AssociativeArray

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