Commit e64deb74 by Iain Buclaw Committed by Iain Buclaw

d: Use semanticRun to prevent declaration pass from running multiple times.

This shouldn't happen during normal traversal of the AST provided from
the front-end, however as there are some cases where declarations need
to be visited out of order, such as what is being done in PR d/89017, it
then becomes necessary to guard against this.

gcc/d/ChangeLog:

2019-04-21  Iain Buclaw  <ibuclaw@gdcproject.org>

	* decl.cc (DeclVisitor::visit(Import)): Set semanticRun after
	completion, guard against being called more than once.
	(DeclVisitor::visit(StructDeclaration)): Likewise.
	(DeclVisitor::visit(ClassDeclaration)): Likewise.
	(DeclVisitor::visit(InterfaceDeclaration)): Likewise.
	(DeclVisitor::visit(VarDeclaration)): Likewise.
	(DeclVisitor::visit(TypeInfoDeclaration)): Likewise.

From-SVN: r270478
parent f452f0d6
2019-04-21 Iain Buclaw <ibuclaw@gdcproject.org> 2019-04-21 Iain Buclaw <ibuclaw@gdcproject.org>
* decl.cc (DeclVisitor::visit(Import)): Set semanticRun after
completion, guard against being called more than once.
(DeclVisitor::visit(StructDeclaration)): Likewise.
(DeclVisitor::visit(ClassDeclaration)): Likewise.
(DeclVisitor::visit(InterfaceDeclaration)): Likewise.
(DeclVisitor::visit(VarDeclaration)): Likewise.
(DeclVisitor::visit(TypeInfoDeclaration)): Likewise.
2019-04-21 Iain Buclaw <ibuclaw@gdcproject.org>
* modules.cc (register_module_decl): Don't register unittests against * modules.cc (register_module_decl): Don't register unittests against
the ModuleInfo symbol for -fbuilding-libphobos-tests. the ModuleInfo symbol for -fbuilding-libphobos-tests.
......
...@@ -152,6 +152,9 @@ public: ...@@ -152,6 +152,9 @@ public:
void visit (Import *d) void visit (Import *d)
{ {
if (d->semanticRun >= PASSobj)
return;
/* Implements import declarations by telling the debug back-end we are /* Implements import declarations by telling the debug back-end we are
importing the NAMESPACE_DECL of the module or IMPORTED_DECL of the importing the NAMESPACE_DECL of the module or IMPORTED_DECL of the
declaration into the current lexical scope CONTEXT. NAME is set if declaration into the current lexical scope CONTEXT. NAME is set if
...@@ -193,6 +196,8 @@ public: ...@@ -193,6 +196,8 @@ public:
debug_hooks->imported_module_or_decl (decl, name, context, debug_hooks->imported_module_or_decl (decl, name, context,
false, false); false, false);
} }
d->semanticRun = PASSobj;
} }
/* Expand any local variables found in tuples. */ /* Expand any local variables found in tuples. */
...@@ -349,6 +354,9 @@ public: ...@@ -349,6 +354,9 @@ public:
void visit (StructDeclaration *d) void visit (StructDeclaration *d)
{ {
if (d->semanticRun >= PASSobj)
return;
if (d->type->ty == Terror) if (d->type->ty == Terror)
{ {
error_at (make_location_t (d->loc), error_at (make_location_t (d->loc),
...@@ -400,6 +408,8 @@ public: ...@@ -400,6 +408,8 @@ public:
if (d->xhash) if (d->xhash)
d->xhash->accept (this); d->xhash->accept (this);
d->semanticRun = PASSobj;
} }
/* Finish semantic analysis of functions in vtbl for class CD. */ /* Finish semantic analysis of functions in vtbl for class CD. */
...@@ -477,6 +487,9 @@ public: ...@@ -477,6 +487,9 @@ public:
void visit (ClassDeclaration *d) void visit (ClassDeclaration *d)
{ {
if (d->semanticRun >= PASSobj)
return;
if (d->type->ty == Terror) if (d->type->ty == Terror)
{ {
error_at (make_location_t (d->loc), error_at (make_location_t (d->loc),
...@@ -542,6 +555,8 @@ public: ...@@ -542,6 +555,8 @@ public:
tree ctype = TREE_TYPE (build_ctype (d->type)); tree ctype = TREE_TYPE (build_ctype (d->type));
if (TYPE_NAME (ctype)) if (TYPE_NAME (ctype))
d_pushdecl (TYPE_NAME (ctype)); d_pushdecl (TYPE_NAME (ctype));
d->semanticRun = PASSobj;
} }
/* Write out compiler generated TypeInfo and vtables for the given interface /* Write out compiler generated TypeInfo and vtables for the given interface
...@@ -549,6 +564,9 @@ public: ...@@ -549,6 +564,9 @@ public:
void visit (InterfaceDeclaration *d) void visit (InterfaceDeclaration *d)
{ {
if (d->semanticRun >= PASSobj)
return;
if (d->type->ty == Terror) if (d->type->ty == Terror)
{ {
error_at (make_location_t (d->loc), error_at (make_location_t (d->loc),
...@@ -581,6 +599,8 @@ public: ...@@ -581,6 +599,8 @@ public:
tree ctype = TREE_TYPE (build_ctype (d->type)); tree ctype = TREE_TYPE (build_ctype (d->type));
if (TYPE_NAME (ctype)) if (TYPE_NAME (ctype))
d_pushdecl (TYPE_NAME (ctype)); d_pushdecl (TYPE_NAME (ctype));
d->semanticRun = PASSobj;
} }
/* Write out compiler generated TypeInfo and initializer for the given /* Write out compiler generated TypeInfo and initializer for the given
...@@ -630,6 +650,9 @@ public: ...@@ -630,6 +650,9 @@ public:
void visit (VarDeclaration *d) void visit (VarDeclaration *d)
{ {
if (d->semanticRun >= PASSobj)
return;
if (d->type->ty == Terror) if (d->type->ty == Terror)
{ {
error_at (make_location_t (d->loc), error_at (make_location_t (d->loc),
...@@ -755,6 +778,8 @@ public: ...@@ -755,6 +778,8 @@ public:
} }
} }
} }
d->semanticRun = PASSobj;
} }
/* Generate and compile a static TypeInfo declaration, but only if it is /* Generate and compile a static TypeInfo declaration, but only if it is
...@@ -762,12 +787,16 @@ public: ...@@ -762,12 +787,16 @@ public:
void visit (TypeInfoDeclaration *d) void visit (TypeInfoDeclaration *d)
{ {
if (d->semanticRun >= PASSobj)
return;
if (speculative_type_p (d->tinfo)) if (speculative_type_p (d->tinfo))
return; return;
tree t = get_typeinfo_decl (d); tree t = get_typeinfo_decl (d);
DECL_INITIAL (t) = layout_typeinfo (d); DECL_INITIAL (t) = layout_typeinfo (d);
d_finish_decl (t); d_finish_decl (t);
d->semanticRun = PASSobj;
} }
/* Finish up a function declaration and compile it all the way /* Finish up a function declaration and compile it all the way
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment