Skip to content

Commit

Permalink
fix Issue 14306 - Wrong codegen with -inline for generic lambdas
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Mar 20, 2015
1 parent 06537bc commit 03f71be
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/e2ir.c
Expand Up @@ -3306,6 +3306,8 @@ elem *toElem(Expression *e, IRState *irs)
if (tb1->ty != Tclass && tb1->ty != Tpointer)
e = addressElem(e, tb1);
e = el_bin(OPadd, TYnptr, e, el_long(TYsize_t, v->offset));
if (ISREF(v, tyb))
e = el_una(OPind, TYptr, e);
e = el_una(OPind, totym(dve->type), e);
if (tybasic(e->Ety) == TYstruct)
{
Expand Down Expand Up @@ -3406,7 +3408,7 @@ elem *toElem(Expression *e, IRState *irs)

void visit(CallExp *ce)
{
//printf("CallExp::toElem('%s')\n", ce->toChars());
//printf("[%s] CallExp::toElem('%s') %p, %s\n", ce->loc.toChars(), ce->toChars(), ce, ce->type->toChars());
assert(ce->e1->type);
Type *t1 = ce->e1->type->toBasetype();
Type *ectype = t1;
Expand Down
43 changes: 43 additions & 0 deletions test/runnable/inline.d
Expand Up @@ -581,6 +581,48 @@ void test14267()
}
}

/**********************************/
// https://issues.dlang.org/show_bug.cgi?id=14306

struct MapResult(alias fun)
{
void front()
{
// while (1) { break; }
fun(1);
}
}

void bar(R)(R r)
{
foreach (i; 0..100)
{
r.front();
}
}

struct S {
int x;
int bump() {
while (1) { break; }
++x;
return x;
}
}

void fun(ref S s) {
MapResult!(y => s.bump())().bar;
// MapResult!((int x) => s.bump())().bar;


if (s.x != 100) assert(0);
}

void test14306() {
S t;
fun(t);
}

/**********************************/

int main()
Expand All @@ -603,6 +645,7 @@ int main()
test11322();
test11394();
test13503();
test14306();

printf("Success\n");
return 0;
Expand Down

0 comments on commit 03f71be

Please sign in to comment.