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

LDC generates segfaulting code with nested functions #513

Closed
Safety0ff opened this issue Oct 15, 2013 · 10 comments
Closed

LDC generates segfaulting code with nested functions #513

Safety0ff opened this issue Oct 15, 2013 · 10 comments

Comments

@Safety0ff
Copy link

See this code: http://dpaste.dzfl.pl/f2d04ad8
DMD HEAD compiles this fine, whereas LDC compiles it and it crashes on run.
Older DMD gives a compilation error.

@Safety0ff
Copy link
Author

By the way, I've edited the OP to include a reduce test case (instead of the long code I had in the OP).

@dnadlinger
Copy link
Member

Ah, thanks for the comment (editing an issue doesn't trigger a notification on GitHub). This should make the issue much easier to track down, even though there are still Phobos dependencies left.

Regarding "older" DMD versions not accepting the code: Does 2.063.2 accept it? If not, it might be a frontend issue that we need to mitigate by also producing an error message. But that's just speculation without having looked at the test case in any detail, it could be a bug in our nested context handling code just as well.

@Safety0ff
Copy link
Author

I should have been more clear, I did mean DMD 2.063.2 rejected it (master works fine.)
The error was generated from src/toir.c in DMD's source, I don't know which commit fixed it though (maybe the fix for http://d.puremagic.com/issues/show_bug.cgi?id=9578 , I don't know.)

@Safety0ff
Copy link
Author

The test for http://d.puremagic.com/issues/show_bug.cgi?id=9578 from dlang/dmd@98a398b
Also segfaults:

template t9578(alias f) { void tf()() { f(); } }

void g9578a(alias f)()  { f(); }        // Error -> OK
void g9578b(alias ti)() { ti.tf(); }    // Error -> OK

void test9578()
{
    int i = 0;
    int m() { return i; }

    g9578a!(t9578!m.tf)();
    g9578b!(t9578!m)();
}
void main() { test9578(); }

@dnadlinger
Copy link
Member

Even better, thanks. Hope I will be able to look into this tomorrow or so.

@dnadlinger
Copy link
Member

Okay, so this is a frontend bug fixed in dlang/dmd@98a398b. The reason that the code crashes with LDC is that we pass null for the nested context pointer to tf (which is then passed to m) because DMD doesn't provide the necessary information in the AST (see the linked commit). We output null instead of producing an error because the way our glue code is set up, this can also happen in some valid cases.

@dnadlinger
Copy link
Member

As back-porting changes to central pieces of the frontend is rather risky, I don't think we will fix this until 2.064 is merged. It would be good if we could mitigate this by adding a check similar to that in DMD, though.

@dnadlinger
Copy link
Member

Hm, I don't think I'll be able to resolve this (i.e. mitigate the wrong-code issue to an error messages similar to what DMD 2.063.2 gives) on the weekend – somebody else wants to tackle this?

@redstar
Copy link
Member

redstar commented Jan 3, 2014

Fixed in branch merge-2.064.

redstar added a commit that referenced this issue Jan 3, 2014
@redstar
Copy link
Member

redstar commented Feb 4, 2014

Available in release 0.13.0-alpha1.

@redstar redstar closed this as completed Feb 4, 2014
redstar pushed a commit that referenced this issue Sep 27, 2014
Fix logic of pthread type sizes to match C headers.
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

3 participants