Skip to content

Commit

Permalink
Merge pull request #3985 from klickverbot/2.066
Browse files Browse the repository at this point in the history
Cherry-picking pull request #3961 for 2.066.1
  • Loading branch information
9rnsr committed Sep 14, 2014
2 parents 0c0f58a + 021b481 commit 9ca87d2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/inline.c
Expand Up @@ -57,6 +57,7 @@ class InlineCostVisitor : public Visitor
int nested;
int hasthis;
int hdrscan; // !=0 if inline scan for 'header' content
bool allowAlloca;
FuncDeclaration *fd;
int cost;

Expand All @@ -65,6 +66,7 @@ class InlineCostVisitor : public Visitor
nested = 0;
hasthis = 0;
hdrscan = 0;
allowAlloca = false;
fd = NULL;
cost = 0;
}
Expand All @@ -74,6 +76,7 @@ class InlineCostVisitor : public Visitor
nested = icv->nested;
hasthis = icv->hasthis;
hdrscan = icv->hdrscan;
allowAlloca = icv->allowAlloca;
fd = icv->fd;
cost = 0; // zero start for subsequent AST
}
Expand Down Expand Up @@ -370,7 +373,7 @@ class InlineCostVisitor : public Visitor
// can't handle that at present.
if (e->e1->op == TOKdotvar && ((DotVarExp *)e->e1)->e1->op == TOKsuper)
cost = COST_MAX;
else if (e->f && e->f->ident == Id::__alloca && e->f->linkage == LINKc)
else if (e->f && e->f->ident == Id::__alloca && e->f->linkage == LINKc && !allowAlloca)
cost = COST_MAX; // inlining alloca may cause stack overflows
else
cost++;
Expand Down Expand Up @@ -2025,6 +2028,7 @@ Expression *inlineCopy(Expression *e, Scope *sc)

InlineCostVisitor icv;
icv.hdrscan = 1;
icv.allowAlloca = true;
icv.expressionInlineCost(e);
int cost = icv.cost;
if (cost >= COST_MAX)
Expand Down
9 changes: 9 additions & 0 deletions test/runnable/xtest46.d
Expand Up @@ -5622,6 +5622,14 @@ mixin template ProxyOf(alias a)
void test2(this Y)(){}
}

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

import core.stdc.stdlib;

void test13427(void* buffer = alloca(100))
{
}

/***************************************************/
// 7583

Expand Down Expand Up @@ -7248,6 +7256,7 @@ int main()
test8283();
test13182();
test8395();
test13427();
test5749();
test8396();
test160();
Expand Down

0 comments on commit 9ca87d2

Please sign in to comment.