4543 – Regression(1.054, 2.038) typedef circular definition and segfault

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 4543 - Regression(1.054, 2.038) typedef circular definition and segfault
Summary: Regression(1.054, 2.038) typedef circular definition and segfault
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All Linux
: P2 regression
Assignee: No Owner
URL:
Keywords: ice-on-valid-code, patch, rejects-valid
: 3976 (view as issue list)
Depends on:
Blocks:
Reported: 2010年08月01日 04:10 UTC by Iain Buclaw
Modified: 2020年03月10日 23:54 UTC (History)
5 users (show)

See Also:


Attachments
Fix issue4543 segv (482 bytes, patch)
2011年03月01日 08:35 UTC, Iain Buclaw
Details | Diff
issue4543 (1.48 KB, patch)
2011年03月24日 12:24 UTC, Iain Buclaw
Details | Diff
Show Obsolete (1) Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description Iain Buclaw 2010年08月01日 04:10:55 UTC
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
Comment 1 bearophile_hugs 2010年08月01日 05:15:08 UTC
According to Andrei 'typedef' will be removed from the language.
Is an 'alias' there giving the same troubles?
Comment 2 Iain Buclaw 2010年08月01日 05:33:11 UTC
(In reply to comment #1)
> 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...
Comment 3 bearophile_hugs 2010年08月01日 06:18:10 UTC
You are right, typedef will be removed from D1 only.
Comment 4 bearophile_hugs 2010年08月01日 06:19:10 UTC
You are right, typedef will be removed from D2 only.
Comment 5 Don 2010年08月24日 23:55:47 UTC
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.
Comment 6 Don 2010年08月25日 12:42:01 UTC
Bug 3976 is probably a duplicate of this one.
Comment 7 Don 2010年08月26日 07:40:22 UTC
*** Issue 3976 has been marked as a duplicate of this issue. ***
Comment 8 Don 2010年09月29日 00:27:35 UTC
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.
Comment 9 Iain Buclaw 2011年03月01日 08:35:31 UTC
Created attachment 926 [details] 
Fix issue4543 segv
Bump.
Patch to prevent ICE from occurring, but doesn't stop the forward reference error.
Comment 10 Iain Buclaw 2011年03月01日 10:50:34 UTC
And have no testsuite regressions on Linux as a result of the patch.
Comment 11 Iain Buclaw 2011年03月24日 12:24:59 UTC
Created attachment 934 [details] 
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;
 }
}
Comment 12 Iain Buclaw 2011年03月24日 12:41:02 UTC
>--- 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
Comment 14 Dlang Bot 2020年03月10日 23:54:09 UTC
dlang/dmd pull request #10890 "Remove obsolete test for issue 4543" was merged into master:
- e5411c1cbeee57c5875fb6a1d6eb9782d3836cc4 by Geod24:
 Remove obsolete test for issue 4543
 
 Typedef is long gone and the test was typedef-specific.
https://github.com/dlang/dmd/pull/10890 


AltStyle によって変換されたページ (->オリジナル) /