Skip to content

Commit

Permalink
fix Issue 14267 - ICE when determining if a function can be inlined
Browse files Browse the repository at this point in the history
  • Loading branch information
9rnsr committed Mar 10, 2015
1 parent 942dffe commit e5e7ddc
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 5 deletions.
25 changes: 20 additions & 5 deletions src/func.c
Expand Up @@ -4572,6 +4572,8 @@ Dsymbol *CtorDeclaration::syntaxCopy(Dsymbol *s)
void CtorDeclaration::semantic(Scope *sc)
{
//printf("CtorDeclaration::semantic() %s\n", toChars());
if (semanticRun >= PASSsemanticdone)
return;
if (scope)
{
sc = scope;
Expand Down Expand Up @@ -4664,6 +4666,8 @@ void PostBlitDeclaration::semantic(Scope *sc)
//printf("PostBlitDeclaration::semantic() %s\n", toChars());
//printf("ident: %s, %s, %p, %p\n", ident->toChars(), Id::dtor->toChars(), ident, Id::dtor);
//printf("stc = x%llx\n", sc->stc);
if (semanticRun >= PASSsemanticdone)
return;
if (scope)
{
sc = scope;
Expand Down Expand Up @@ -4734,6 +4738,8 @@ void DtorDeclaration::semantic(Scope *sc)
{
//printf("DtorDeclaration::semantic() %s\n", toChars());
//printf("ident: %s, %s, %p, %p\n", ident->toChars(), Id::dtor->toChars(), ident, Id::dtor);
if (semanticRun >= PASSsemanticdone)
return;
if (scope)
{
sc = scope;
Expand Down Expand Up @@ -4816,7 +4822,8 @@ Dsymbol *StaticCtorDeclaration::syntaxCopy(Dsymbol *s)
void StaticCtorDeclaration::semantic(Scope *sc)
{
//printf("StaticCtorDeclaration::semantic()\n");

if (semanticRun >= PASSsemanticdone)
return;
if (scope)
{
sc = scope;
Expand Down Expand Up @@ -4929,6 +4936,8 @@ Dsymbol *StaticDtorDeclaration::syntaxCopy(Dsymbol *s)

void StaticDtorDeclaration::semantic(Scope *sc)
{
if (semanticRun >= PASSsemanticdone)
return;
if (scope)
{
sc = scope;
Expand Down Expand Up @@ -5036,6 +5045,8 @@ Dsymbol *InvariantDeclaration::syntaxCopy(Dsymbol *s)

void InvariantDeclaration::semantic(Scope *sc)
{
if (semanticRun >= PASSsemanticdone)
return;
if (scope)
{
sc = scope;
Expand Down Expand Up @@ -5111,14 +5122,16 @@ Dsymbol *UnitTestDeclaration::syntaxCopy(Dsymbol *s)

void UnitTestDeclaration::semantic(Scope *sc)
{
protection = sc->protection;

if (semanticRun >= PASSsemanticdone)
return;
if (scope)
{
sc = scope;
scope = NULL;
}

protection = sc->protection;

if (inNonRoot())
return;

Expand Down Expand Up @@ -5188,7 +5201,8 @@ Dsymbol *NewDeclaration::syntaxCopy(Dsymbol *s)
void NewDeclaration::semantic(Scope *sc)
{
//printf("NewDeclaration::semantic()\n");

if (semanticRun >= PASSsemanticdone)
return;
if (scope)
{
sc = scope;
Expand Down Expand Up @@ -5264,7 +5278,8 @@ Dsymbol *DeleteDeclaration::syntaxCopy(Dsymbol *s)
void DeleteDeclaration::semantic(Scope *sc)
{
//printf("DeleteDeclaration::semantic()\n");

if (semanticRun >= PASSsemanticdone)
return;
if (scope)
{
sc = scope;
Expand Down
19 changes: 19 additions & 0 deletions test/runnable/imports/a14267.d
@@ -0,0 +1,19 @@
module imports.a14267;

struct SysTime14267
{
// semantic() is called twice, and its scope is wrongly set to NULL
// at the second call.
this(long stdTime) {}
this(this) {}
~this() {}

static SysTime14267 min()
{
// inlining this function will call the semantic3() of SysTime14267 constructor.
// but its 'scope' field is NULL so unintentionally semantic3() call fails.
auto st = SysTime14267(long.min);
auto st2 = st;
return st2;
}
}
25 changes: 25 additions & 0 deletions test/runnable/inline.d
Expand Up @@ -556,6 +556,31 @@ void test13503()
f13503a(f13503c("Cheese"));
}

/**********************************/
// 14267

// EXTRA_SOURCES: imports/a14267.d
import imports.a14267;

void test14267()
{
foreach (m; __traits(allMembers, SysTime14267))
{
static if (is(typeof(__traits(getMember, SysTime14267, m))))
{
foreach (func; __traits(getOverloads, SysTime14267, m))
{
auto prot = __traits(getProtection, func);
static if (__traits(isStaticFunction, func))
{
static assert(func.stringof == "min()");
auto result = func;
}
}
}
}
}

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

int main()
Expand Down

0 comments on commit e5e7ddc

Please sign in to comment.