The Semantic (pass 1) analysis for classes is handled by
ClassDeclaration::semantic. For a given class, this method may be ran
multiple times in order to resolve forward references. The method
incrementally tries to resolve the types referred to by the members of
the class.
The subsequent calls to this method are short-circuited if the class
members have been fully analyzed. For this the code tests that it is
not the first/main call to the method (semanticRun == PASS.init else
branch), scx is not set, and that the this->symtab is already set. If
all these conditions are met, the method returns. But before returning,
the method was setting this->semanticRun to PASSsemanticdone. It should
not set semanticRun since the class has not been fully analyzed yet.
The base class analysis for this class could be pending and as a result
vtable may not have been fully created.
This fake setting of semanticRun results in the semantic analyzer to
believe that the class has been fully analyzed. As exposed by the
issues in upstream, it may result in compile time errors when a derived
type class is getting analyzed and because of this fake semanticdone on
the base class, the semantic analysis construes that an overriden method
is not defined in the base class. PR95155 exposes anoter scenario where
a buggy vtable may be created and a call to a class method may result in
execution of some adhoc code.
gcc/d/ChangeLog:
PR d/95155
* dmd/dclass.c (ClassDeclaration::semantic): Don't prematurely
set done on semantic analysis.
gcc/testsuite/ChangeLog:
PR d/95155
* gdc.test/compilable/imports/pr9471a.d: New test.
* gdc.test/compilable/imports/pr9471b.d: New test.
* gdc.test/compilable/imports/pr9471c.d: New test.
* gdc.test/compilable/imports/pr9471d.d: New test.
* gdc.test/compilable/pr9471.d: New test.
+2020-05-16 Iain Buclaw <ibuclaw@gdcproject.org>
+
+ PR d/95155
+ * dmd/dclass.c (ClassDeclaration::semantic): Don't prematurely
+ set done on semantic analysis.
+
2020-04-07 Iain Buclaw <ibuclaw@gdcproject.org>
PR d/94240
}
else if (symtab && !scx)
{
- semanticRun = PASSsemanticdone;
return;
}
semanticRun = PASSsemantic;
+2020-05-16 Iain Buclaw <ibuclaw@gdcproject.org>
+
+ PR d/95155
+ * gdc.test/compilable/imports/pr9471a.d: New test.
+ * gdc.test/compilable/imports/pr9471b.d: New test.
+ * gdc.test/compilable/imports/pr9471c.d: New test.
+ * gdc.test/compilable/imports/pr9471d.d: New test.
+ * gdc.test/compilable/pr9471.d: New test.
+
2020-05-14 Szabolcs Nagy <szabolcs.nagy@arm.com>
Backport from mainline.
--- /dev/null
+import imports.pr9471c;
+class AggregateDeclaration : ScopeDsymbol { }
--- /dev/null
+import imports.pr9471a;
+class ClassDeclaration : AggregateDeclaration
+{
+ void isBaseOf();
+}
--- /dev/null
+import imports.pr9471b;
+
+struct Array(T)
+{
+ static if (is(typeof(T.opCmp))) { }
+}
+alias ClassDeclarations = Array!ClassDeclaration;
+
+class Dsymbol
+{
+ void addObjcSymbols(ClassDeclarations);
+}
+
+class ScopeDsymbol : Dsymbol
+{
+ import imports.pr9471d;
+ void importScope();
+}
--- /dev/null
+// Module needs to be imported to trigger bug.
--- /dev/null
+// PERMUTE_ARGS:
+// EXTRA_FILES: imports/pr9471a.d imports/pr9471b.d imports/pr9471c.d imports/pr9471d.d
+import imports.pr9471a;
+import imports.pr9471b;
+
+static assert (__traits(getVirtualIndex, ClassDeclaration.isBaseOf) == 7);