Skip to content

Commit

Permalink
fix fix Issue 12231 - ICE on the class declaration within lambda insi…
Browse files Browse the repository at this point in the history
…de template constraint
  • Loading branch information
9rnsr committed Mar 5, 2014
1 parent 7af184f commit e0e261b
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 25 deletions.
11 changes: 5 additions & 6 deletions src/expression.c
Expand Up @@ -5477,12 +5477,13 @@ void FuncExp::genIdent(Scope *sc)
DsymbolTable *symtab;
if (FuncDeclaration *func = sc->parent->isFuncDeclaration())
{
symtab = func->localsymtab;
if (symtab)
if (func->localsymtab == NULL)
{
// Inside template constraint, symtab is not set yet.
goto L1;
// Initialize it lazily.
func->localsymtab = new DsymbolTable();
}
symtab = func->localsymtab;
}
else
{
Expand All @@ -5496,9 +5497,7 @@ void FuncExp::genIdent(Scope *sc)
}
symtab = sds->symtab;
}
if (!symtab)
return;
L1:
assert(symtab);
int num = (int)_aaLen(symtab->tab) + 1;
Identifier *id = Lexer::uniqueId(s, num);
fd->ident = id;
Expand Down
12 changes: 11 additions & 1 deletion src/template.c
Expand Up @@ -806,11 +806,13 @@ bool TemplateDeclaration::evaluateConstraint(
scx = scx->startCTFE();
scx->flags |= SCOPEstaticif;
assert(ti->inst == NULL);
ti->inst = ti; // temporary instantiation to enable genIdent()

//printf("\tscx->parent = %s %s\n", scx->parent->kind(), scx->parent->toPrettyChars());
e = e->semantic(scx);
e = resolveProperties(scx, e);

ti->inst = NULL;
ti->symtab = NULL;
scx = scx->endCTFE();

Expand Down Expand Up @@ -971,6 +973,7 @@ MATCH TemplateDeclaration::matchWithInstance(Scope *sc, TemplateInstance *ti,
// Resolve parameter types and 'auto ref's.
tf->fargs = fargs;
fd->type = tf->semantic(loc, paramscope);
fd->originalType = fd->type; // for mangling
if (fd->type->ty != Tfunction)
goto Lnomatch;
}
Expand Down Expand Up @@ -2600,6 +2603,7 @@ FuncDeclaration *TemplateDeclaration::doHeaderInstantiation(
fd->type = tf;
fd->type = fd->type->addSTC(scx->stc);
fd->type = fd->type->semantic(fd->loc, scx);
fd->originalType = fd->type; // for mangling
//printf("\t[%s] fd->type = %s, mod = %x, ", loc.toChars(), fd->type->toChars(), fd->type->mod);
//printf("fd->needThis() = %d\n", fd->needThis());

Expand Down Expand Up @@ -7090,7 +7094,13 @@ Identifier *TemplateInstance::genIdent(Objects *args)
//printf("TemplateInstance::genIdent('%s')\n", tempdecl->ident->toChars());
OutBuffer buf;
char *id = tempdecl->ident->toChars();
buf.printf("__T%llu%s", (ulonglong)strlen(id), id);
if (!members)
{
// Use "__U" for the symbols declared inside template constraint.
buf.printf("__U%llu%s", (ulonglong)strlen(id), id);
}
else
buf.printf("__T%llu%s", (ulonglong)strlen(id), id);
for (size_t i = 0; i < args->dim; i++)
{
RootObject *o = (*args)[i];
Expand Down
18 changes: 0 additions & 18 deletions src/toobj.c
Expand Up @@ -1161,24 +1161,6 @@ void TemplateInstance::toObjFile(int multiobj)
#endif
if (!isError(this) && members)
{
FuncDeclaration *fd = enclosing ? enclosing->isFuncDeclaration() : NULL;
if (fd && fd->fbody == NULL)
{
/* Prevent codegen if enclosing is an artificially instantiated function.
*/
return;
}

TemplateDeclaration *tempdecl = this->tempdecl->isTemplateDeclaration();
assert(tempdecl);
if (tempdecl->literal && tempdecl->ident == Id::empty)
{
/* Bugzilla 10313: Template lambdas that instantiated in template constraint
* cannot appear in runnable code block. So, this skip won't cause linker failure.
*/
return;
}

if (multiobj)
// Append to list of object files to be written later
obj_append(this);
Expand Down
69 changes: 69 additions & 0 deletions test/runnable/mangle.d
Expand Up @@ -393,6 +393,75 @@ void test12217(int)

void test12217() {}

/***************************************************/
// 12231

void func12231a()()
if (is(typeof({
class C {}
static assert(C.mangleof ==
"C6mangle16__U10func12231aZ10func12231aFZ9__lambda1MFZ1C");
// ### L #
})))
{}

void func12231b()()
if (is(typeof({
class C {}
static assert(C.mangleof ==
"C6mangle16__U10func12231bZ10func12231bFZ9__lambda1MFZ1C");
// L__L L LL
})) &&
is(typeof({
class C {}
static assert(C.mangleof ==
"C6mangle16__U10func12231bZ10func12231bFZ9__lambda2MFZ1C");
// L__L L LL
})))
{}

void func12231c()()
if (is(typeof({
class C {}
static assert(C.mangleof ==
"C6mangle16__U10func12231cZ10func12231cFZ9__lambda1MFZ1C");
// L__L L LL
})))
{
(){
class C {}
static assert(C.mangleof ==
"C6mangle16__T10func12231cZ10func12231cFZ9__lambda1MFZ1C");
// L__L L LL
}();
}

void func12231c(X)()
if (is(typeof({
class C {}
static assert(C.mangleof ==
"C6mangle20__U10func12231cTAyaZ10func12231cFZ9__lambda1MFZ1C");
// L__L L___L LL
})))
{
(){
class C {}
static assert(C.mangleof ==
"C6mangle20__T10func12231cTAyaZ10func12231cFZ9__lambda1MFZ1C");
// L__L L___L LL
}();
}

void test12231()
{
func12231a();

func12231b();

func12231c();
func12231c!string();
}

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

void main()
Expand Down

0 comments on commit e0e261b

Please sign in to comment.