Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dangling TemplateInstance.tinst if set to a dummy instance created by leastAsSpecialized() #19525

Open
dlangBugzillaToGithub opened this issue Jan 11, 2019 · 0 comments

Comments

@dlangBugzillaToGithub
Copy link

Elie Morisse (@Syniurge) reported this on 2019-01-11T17:42:14Z

Transferred from https://issues.dlang.org/show_bug.cgi?id=19576

Description

Created attachment 1724
Backtrace of Calypso (based on LDC 1.10) building Phobos

In dtemplate.d's leastAsSpecialized():

        scope TemplateInstance ti = new TemplateInstance(Loc.initial, ident, tiargs); // create dummy template instance

// ...

        MATCH m = td2.matchWithInstance(sc, ti, &dedtypes, fargs, 1);

If td2 has a default template argument, matchWithInstance may lead to more template instantiations and those will end up with a dangling .tinst pointer.

The problematic dummy template instance in my case was:

  void encode(UseReplacementDchar useReplacementDchar = No.useReplacementDchar)

in phobos/std/utf.d, which instantiated No.opDispatch:

  struct No  // in phobos/std/typecons.d
  {
      template opDispatch(string name)

And this opDispatch template instance got its .tinst member set to the dummy instance, so became dangling as soon as leastAsSpecialized returned.

I couldn't reproduce a simple segfaulting case. It was triggered with Calypso (that I recently updated from LDC 1.7 to LDC 1.10) and the error occurred during codegen while compiling Phobos's std/utf.d. LDC's codegen was calling calling TemplateInstance.isCodegen(), which went through the siblings to make a decision and ended up examining the instance with the dangling .tinst. But it didn't segfault straightaway (see attached backtrace, the instance with dangling .tinst is actually 'this' of #8), isCodegen managed to survive with garbage TemplateInstance pointers, which is why it's hard to reproduce.

I wrote a tentative fix for Calypso: https://github.com/Syniurge/Calypso/commit/16336e5a6235e113c6d3bebe043d34234f1e80aa
Should I make a PR for DMD or is there a better way to fix it?

!!!There are attachements in the bugzilla issue that have not been copied over!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant