Skip to content

Commit

Permalink
fix Issue 15200 - ICE(glue.c) when compiling with -inline
Browse files Browse the repository at this point in the history
Even if a function is expanded by inlining, the function itself don't have to put in object file. In short, adjusting `ti.minst` in `inline.d` is not correct.

The unspeculation in `expandInline` was added in the PR #4944, but sadly it was just a hack and inherently unneeded. The changes in `TemplateInstance.appendToModuleMember` and `needsCodegen` those were added since 2.068.1-b1, now correctly handle codegen of nested template instances.
  • Loading branch information
9rnsr committed Oct 13, 2015
1 parent d752f69 commit 204df57
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/dtemplate.d
Original file line number Diff line number Diff line change
Expand Up @@ -7346,8 +7346,8 @@ public:
}
//printf("%s->appendToModuleMember() enclosing = %s mi = %s\n",
// toPrettyChars(),
// enclosing ? enclosing.toPrettyChars() : NULL,
// mi ? mi.toPrettyChars() : NULL);
// enclosing ? enclosing.toPrettyChars() : null,
// mi ? mi.toPrettyChars() : null);
if (!mi || mi.isRoot())
{
/* If the instantiated module is speculative or root, insert to the
Expand Down
8 changes: 0 additions & 8 deletions src/inline.d
Original file line number Diff line number Diff line change
Expand Up @@ -1948,14 +1948,6 @@ void expandInline(FuncDeclaration fd, FuncDeclaration parent, Expression eret,
}
scope ids = new InlineDoState(parent, fd);

// When the function is actually expanded
if (TemplateInstance ti = fd.isInstantiated())
{
// change ti to non-speculative root instance
if (!ti.minst)
ti.minst = ti.tempdecl.getModule().importedFrom;
}

if (asStatements)
as = new Statements();
VarDeclaration vret = null;
Expand Down
11 changes: 11 additions & 0 deletions test/runnable/ice15200.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// EXTRA_SOURCES: imports/ice15200a.d imports/ice15200b.d
// COMPILE_SEPARATELY

module ice15200;

import imports.ice15200a;

void main()
{
f();
}
12 changes: 12 additions & 0 deletions test/runnable/imports/ice15200a.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import imports.ice15200b;

auto f() // not void
{
sub([0], false);
}
void sub(R)(R list, bool b)
{
foreach (i; list.filter!(delegate(e) => b))
{
}
}
41 changes: 41 additions & 0 deletions test/runnable/imports/ice15200b.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
module imports.ice15200b;

template filter(alias pred)
{
auto filter(R)(R range)
{
return FilterResult!(pred, R)(range);
}
}

struct FilterResult(alias pred, R)
{
R _input;

this(R r)
{
_input = r;
while (_input.length && !pred(_input[0]))
{
_input = _input[1..$];
}
}

@property bool empty()
{
return _input.length == 0;
}

@property auto ref front()
{
return _input[0];
}

void popFront()
{
do
{
_input = _input[1..$];
} while (_input.length && !pred(_input[0]));
}
}

0 comments on commit 204df57

Please sign in to comment.