D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 19465 - dmd segfaults on endless mixin recursion
Summary: dmd segfaults on endless mixin recursion
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 major
Assignee: No Owner
URL:
Keywords: ice
Depends on:
Blocks:
 
Reported: 2018-12-04 14:14 UTC by Dennis
Modified: 2024-12-13 19:01 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Dennis 2018-12-04 14:14:03 UTC
Code:
```
enum string s = "__traits(compiles, mixin(s))";

static if (__traits(compiles, mixin(s))) {
    enum b = 2;
}
```

Output:
Segmentation fault (core dumped)

Concocted example, not something I encountered in actual code. Still, "dmd should never segfault" so filing this as a minor bug.
Comment 1 Stefan Koch 2018-12-04 16:43:06 UTC
Hmm, I think if you are asking for a stack-overflow you should not be surprised if you get it.

This is one of these problems which you get by interpreting a turing-complete language at compile-time.

Introducing an artificial recursion limit has been done, but people (weka) had to increase it in their fork.

Checking for a limit is not _huge_ deal but it is work which does not have to be done.
Comment 2 Dennis 2018-12-04 21:42:58 UTC
Yeah, I don't know if/how this should be "fixed", but notably endless recursion in CTFE:
`` 
enum a = f();
int f() {return f();}
```
Results in:
Error: function `onlineapp.f` CTFE recursion limit exceeded

While endless recursion in mixin without __traits(compiles, ...):
```
enum string s = "mixin(s);";
mixin(s);
```
Results in, after a while:
Error: out of memory
Comment 3 dlangBugzillaToGithub 2024-12-13 19:01:32 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/19514

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB