[Bug 231] Some template mixins symbols get defined in output object files, although they shouldn't

via D.gnu d.gnu at puremagic.com
Tue Jul 26 03:29:17 PDT 2016


http://bugzilla.gdcproject.org/show_bug.cgi?id=231

Johannes Pfau <johannespfau at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ibuclaw at gdcproject.org,
                   |                            |johannespfau at gmail.com

--- Comment #1 from Johannes Pfau <johannespfau at gmail.com> ---
I've tracked this down:

widget.d
--------------------------------------
interface ImplementorIF
{
    void* getImplementorStruct();
    void* getStruct();
}
template ImplementorT()
{
    void* getImplementorStruct()
    {
        return null;
    }
}
class Widget : ImplementorIF
{
    mixin ImplementorT;
    void* getStruct()
    {
        return null;
    }
}
--------------------------------------

range.d
--------------------------------------
import Widget;
class Range : Widget
{
    void* getStruct()
    {
        return null;
    }
}
void main() {}
--------------------------------------
gdc range.d widget.d


The problem is our thunk emission. We call toObjfile in
FuncDeclaration::toThunkSymbol, DMD does not. This code was initially added in
cbd6d919559697bba6bb210acc2761ae43dbaf8a to fix issue 27. Back then we had a
output_declaration_p check in toObjfile that prevented emitting
getImplementorStruct. 9766ddee234a3db05b24d071bd15987373d962f5 changed the
output_declaration_p check into a simple gcc_attribute_p(this) check which
caused this regression.

I wonder how dmd handles issue 27 without calling toObjfile and whether we
should do the same thing. If we have to keep calling toObjfile I think we need
to re-add this code to toObjfile:

--------------------------------------
FuncDeclaration *fd = dsym->isFuncDeclaration();
if (fd != NULL)
  {
    for (FuncDeclaration *fdp = fd; fdp != NULL;)
      {
        if (!fdp->isInstantiated() && fdp->inNonRoot())
          return false;

        if (!fdp->isNested())
          break;

        fdp = fdp->toParent2()->isFuncDeclaration();
      }
  }

  if (!flag_emit_templates)
    return !D_DECL_IS_TEMPLATE (dsym->toSymbol()->Stree);
--------------------------------------

What do you think, Iain?

-- 
You are receiving this mail because:
You are watching all bug changes.


More information about the D.gnu mailing list