www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4543] New: typedef circular definition and ICE

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4543

           Summary: typedef circular definition and ICE
           Product: D
           Version: D1
          Platform: All
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: ibuclaw ubuntu.com



In DMD 1.049, this code used to work:

--
bug01a.d
----------
module bug01a;
import bug01b;
union any {}
typedef any ANY;

--
bug01b.d
-----------
module bug01b;
import bug01a;
struct circular_definition {
    union {
        ANY subany;
    }
}

Later (not sure when, but have tested on DMD 1.059) - this code began failing
with the message:

bug01a.d(4): Error: typedef bug01a.ANY circular definition


Now - this code fails and ICE's the compiler:

bug01a.d(4): Error: typedef bug01a.ANY circular definition
Segmentation fault


Other things to note about the bug, swapping the typedef and union declaration
in bug01a.d works

--
bug02a.d
----------
module bug02a;
import bug02b;
typedef any ANY;
union any {}


However, adding another struct in the second module triggers it again

--
bug02b.d
----------
module bug02b;
import bug02a;
struct circular_definition {
    union {
        ANY subany;
    }
}
struct triggers_bug {}


And ultimately, putting the import at the bottom means it compiles successfully
all the time.

--
works01a.d
----------
module works01a;
typedef any ANY;
union any {}
import works01b;


Regards

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 01 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4543


bearophile_hugs eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs eml.cc



According to Andrei 'typedef' will be removed from the language.
Is an 'alias' there giving the same troubles?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 01 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4543





 According to Andrei 'typedef' will be removed from the language.
 Is an 'alias' there giving the same troubles?
That it does not. Also, I thought typedef was being removed only for D2? This is sad news for me... -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Aug 01 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4543




You are right, typedef will be removed from D1 only.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 01 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4543




You are right, typedef will be removed from D2 only.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 01 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4543


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug yahoo.com.au
           Severity|normal                      |regression


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 17 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4543


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Version|D1                          |D1 & D2
            Summary|typedef circular definition |Regression(1.054, 2.038)
                   |and ICE                     |typedef circular definition
                   |                            |and segfault



Both of the unions in the test case can be replaced with structs without
changing the behaviour.
The union inside circular_definition must be anonymous. If it is given a name, 
compilation succeeds.
Also, if  union any {} is changed into: alias int any; then it segfaults on
2.038.
So the fact that it started segfaulting on the union case is probably not
important.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 24 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4543




Bug 3976 is probably a duplicate of this one.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 25 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4543


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ellery-newcomer utulsa.edu



*** Issue 3976 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 26 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4543




Caused by svn 318, which was fixing bug 282 "Bizarre circular import nested
name invisibility issue". Regression bug 3682 was introduced at the same time.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 29 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4543




Created an attachment (id=926)
Fix issue4543 segv

Bump.

Patch to prevent ICE from occurring, but doesn't stop the forward reference
error.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 01 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4543




---
And have no testsuite regressions on Linux as a result of the patch.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 01 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4543


Iain Buclaw <ibuclaw ubuntu.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------

           obsolete|                            |



---
Created an attachment (id=934)
issue4543

Attached fix for this issue.

Formal testcase:
=== a4543.d ===
import b4543;

class bclass {};
typedef bclass Tclass;

struct bstruct {}
typedef bstruct Tstruct;

=== b4543.d ===
import a4543;

class A {
    struct {
        Tclass a;
        Tstruct b;
    }
    union {
        Tclass c;
        Tstruct d;
    }
}

struct B {
    struct {
        Tclass a;
        Tstruct b;
    }
    union {
        Tclass c;
        Tstruct d;
    }
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 24 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4543




---
--- a/src/class.c
+++ b/src/class.c
   -870,14 +870,14    Dsymbol *ClassDeclaration::search(Loc loc, Identifier
*ident, int flags)
     Dsymbol *s;
     //printf("%s.ClassDeclaration::search('%s')\n", toChars(),
ident->toChars());
 
-    if (scope)
+    if (scope && !symtab)
     {   Scope *sc = scope;
         sc->mustsemantic++;
         semantic(sc);
         sc->mustsemantic--;
     }
 
-    if (!members || !symtab || scope)
+    if (!members || !symtab)
     {
         error("is forward referenced when looking for '%s'", ident->toChars());
         //*(char*)0=0;
Here (and in StructDeclaration), if (!symtab) looks to be a sure sign that the semantic pass hasn't been started yet. Also, if (!members), the semantic won't run anyway, so you are in trouble even if you do call the semantic in the search method. Extending the condition instead to (scope && !symtab) is enough to fix/bypass the forward reference errors for StructDeclaration's while not hurting bug282 which depends on the semantic being called. As for ClassDeclaration's, something extra is needed (as you can see above), I'm not sure of the importance of (scope) *needing* to be NULL here, but removing the check doesn't seem to harm (at least) the testsuite. Regards -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Mar 24 2011
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4543


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla digitalmars.com
         Resolution|                            |FIXED



15:23:54 PDT ---
https://github.com/D-Programming-Language/dmd/commit/c9860015025ce73088d8765e83b0b7bc106237e9

https://github.com/D-Programming-Language/dmd/commit/0c68e90db36a2549ccf9d946af803e726b573e07

https://github.com/D-Programming-Language/dmd/commit/930e029c037c48e3444f0ad657719d9f5b5d23c6

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