aboutsummaryrefslogtreecommitdiff
path: root/gcc/d
diff options
context:
space:
mode:
authorIain Buclaw <ibuclaw@gdcproject.org>2021-04-08 20:24:07 +0200
committerIain Buclaw <ibuclaw@gdcproject.org>2021-04-10 15:02:07 +0200
commit0344b5b822b310921a432b9ffcb9ea0b3964820d (patch)
treefff53c66505d273342310df994491d6e1ca6bd68 /gcc/d
parentd118ec221dd5fc829d2170c257e10b8159dce274 (diff)
downloadgcc-0344b5b822b310921a432b9ffcb9ea0b3964820d.zip
gcc-0344b5b822b310921a432b9ffcb9ea0b3964820d.tar.gz
gcc-0344b5b822b310921a432b9ffcb9ea0b3964820d.tar.bz2
d: Merge upstream dmd 0450061c8
D front-end changes: - Fix ICE in forward referenced type members of structs. - Fix ICE passing a member template mixin identifier as alias argument. - Fix ICE when `__traits' prints error involving a Parameter. - Fix bugs found in `__traits(allMembers)' returning wrong result. - Detect and shortcut Alias and AliasSeq template patterns. Reviewed-on: https://github.com/dlang/dmd/pull/12405 https://github.com/dlang/dmd/pull/12411 gcc/d/ChangeLog: * dmd/MERGE: Merge upstream dmd 0450061c8.
Diffstat (limited to 'gcc/d')
-rw-r--r--gcc/d/dmd/MERGE2
-rw-r--r--gcc/d/dmd/dstruct.c2
-rw-r--r--gcc/d/dmd/dsymbol.h2
-rw-r--r--gcc/d/dmd/dsymbolsem.c65
-rw-r--r--gcc/d/dmd/dtemplate.c59
-rw-r--r--gcc/d/dmd/hdrgen.c4
-rw-r--r--gcc/d/dmd/mtype.c9
-rw-r--r--gcc/d/dmd/template.h2
-rw-r--r--gcc/d/dmd/traits.c12
-rw-r--r--gcc/d/dmd/typesem.c8
-rw-r--r--gcc/d/dmd/version.h2
11 files changed, 150 insertions, 17 deletions
diff --git a/gcc/d/dmd/MERGE b/gcc/d/dmd/MERGE
index 98c229d..86fb308 100644
--- a/gcc/d/dmd/MERGE
+++ b/gcc/d/dmd/MERGE
@@ -1,4 +1,4 @@
-d16195406e1795ee91f2acb8f522fcb4ec698f47
+0450061c8de71328815da9323bd35c92b37d51d2
The first line of this file holds the git revision number of the last
merge done from the dlang/dmd repository.
diff --git a/gcc/d/dmd/dstruct.c b/gcc/d/dmd/dstruct.c
index 40c67ce..9862159 100644
--- a/gcc/d/dmd/dstruct.c
+++ b/gcc/d/dmd/dstruct.c
@@ -260,6 +260,8 @@ void AggregateDeclaration::setScope(Scope *sc)
*/
bool AggregateDeclaration::determineFields()
{
+ if (_scope)
+ dsymbolSemantic(this, NULL);
if (sizeok != SIZEOKnone)
return true;
diff --git a/gcc/d/dmd/dsymbol.h b/gcc/d/dmd/dsymbol.h
index 4aabb5d..ce0ce45 100644
--- a/gcc/d/dmd/dsymbol.h
+++ b/gcc/d/dmd/dsymbol.h
@@ -266,6 +266,8 @@ public:
virtual UnitTestDeclaration *isUnitTestDeclaration() { return NULL; }
virtual NewDeclaration *isNewDeclaration() { return NULL; }
virtual VarDeclaration *isVarDeclaration() { return NULL; }
+ virtual VersionSymbol *isVersionSymbol() { return NULL; }
+ virtual DebugSymbol *isDebugSymbol() { return NULL; }
virtual ClassDeclaration *isClassDeclaration() { return NULL; }
virtual StructDeclaration *isStructDeclaration() { return NULL; }
virtual UnionDeclaration *isUnionDeclaration() { return NULL; }
diff --git a/gcc/d/dmd/dsymbolsem.c b/gcc/d/dmd/dsymbolsem.c
index 7e1a858..33f74ed 100644
--- a/gcc/d/dmd/dsymbolsem.c
+++ b/gcc/d/dmd/dsymbolsem.c
@@ -570,7 +570,7 @@ public:
ti = dsym->_init ? dsym->_init->syntaxCopy() : NULL;
VarDeclaration *v = new VarDeclaration(dsym->loc, arg->type, id, ti);
- v->storage_class |= STCtemp | dsym->storage_class;
+ v->storage_class |= STCtemp | STClocal | dsym->storage_class;
if (arg->storageClass & STCparameter)
v->storage_class |= arg->storageClass;
//printf("declaring field %s of type %s\n", v->toChars(), v->type->toChars());
@@ -4843,6 +4843,54 @@ public:
}
};
+/******************************************************
+ * Do template instance semantic for isAliasSeq templates.
+ * This is a greatly simplified version of TemplateInstance::semantic().
+ */
+static void aliasSeqInstanceSemantic(TemplateInstance *tempinst, Scope *sc, TemplateDeclaration *tempdecl)
+{
+ //printf("[%s] aliasSeqInstanceSemantic('%s')\n", tempinst->loc.toChars(), tempinst->toChars());
+ Scope *paramscope = sc->push();
+ paramscope->stc = 0;
+ paramscope->protection = Prot(Prot::public_);
+
+ TemplateTupleParameter *ttp = (*tempdecl->parameters)[0]->isTemplateTupleParameter();
+ Tuple *va = isTuple(tempinst->tdtypes[0]);
+ Declaration *d = new TupleDeclaration(tempinst->loc, ttp->ident, &va->objects);
+ d->storage_class |= STCtemplateparameter;
+ dsymbolSemantic(d, sc);
+
+ paramscope->pop();
+
+ tempinst->aliasdecl = d;
+
+ tempinst->semanticRun = PASSsemanticdone;
+}
+
+/******************************************************
+ * Do template instance semantic for isAlias templates.
+ * This is a greatly simplified version of TemplateInstance::semantic().
+ */
+static void aliasInstanceSemantic(TemplateInstance *tempinst, Scope *sc, TemplateDeclaration *tempdecl)
+{
+ //printf("[%s] aliasInstanceSemantic('%s')\n", tempinst->loc.toChars(), tempinst->toChars());
+ Scope *paramscope = sc->push();
+ paramscope->stc = 0;
+ paramscope->protection = Prot(Prot::public_);
+
+ TemplateTypeParameter *ttp = (*tempdecl->parameters)[0]->isTemplateTypeParameter();
+ Type *ta = isType(tempinst->tdtypes[0]);
+ Declaration *d = new AliasDeclaration(tempinst->loc, ttp->ident, ta->addMod(tempdecl->onemember->isAliasDeclaration()->type->mod));
+ d->storage_class |= STCtemplateparameter;
+ dsymbolSemantic(d, sc);
+
+ paramscope->pop();
+
+ tempinst->aliasdecl = d;
+
+ tempinst->semanticRun = PASSsemanticdone;
+}
+
void templateInstanceSemantic(TemplateInstance *tempinst, Scope *sc, Expressions *fargs)
{
//printf("[%s] TemplateInstance::semantic('%s', this=%p, gag = %d, sc = %p)\n", tempinst->loc.toChars(), tempinst->toChars(), tempinst, global.gag, sc);
@@ -4913,6 +4961,21 @@ Lerror:
if (tempinst->errors)
goto Lerror;
+ /* Greatly simplified semantic processing for AliasSeq templates
+ */
+ if (tempdecl->isTrivialAliasSeq)
+ {
+ tempinst->inst = tempinst;
+ return aliasSeqInstanceSemantic(tempinst, sc, tempdecl);
+ }
+ /* Greatly simplified semantic processing for Alias templates
+ */
+ else if (tempdecl->isTrivialAlias)
+ {
+ tempinst->inst = tempinst;
+ return aliasInstanceSemantic(tempinst, sc, tempdecl);
+ }
+
/* See if there is an existing TemplateInstantiation that already
* implements the typeargs. If so, just refer to that one instead.
*/
diff --git a/gcc/d/dmd/dtemplate.c b/gcc/d/dmd/dtemplate.c
index 208b064..20036f2 100644
--- a/gcc/d/dmd/dtemplate.c
+++ b/gcc/d/dmd/dtemplate.c
@@ -222,7 +222,8 @@ bool definitelyValueParameter(Expression *e)
e->op == TOKtype || e->op == TOKdottype ||
e->op == TOKtemplate || e->op == TOKdottd ||
e->op == TOKfunction || e->op == TOKerror ||
- e->op == TOKthis || e->op == TOKsuper)
+ e->op == TOKthis || e->op == TOKsuper ||
+ e->op == TOKdot)
return false;
if (e->op != TOKdotvar)
@@ -531,6 +532,8 @@ TemplateDeclaration::TemplateDeclaration(Loc loc, Identifier *id,
this->literal = literal;
this->ismixin = ismixin;
this->isstatic = true;
+ this->isTrivialAliasSeq = false;
+ this->isTrivialAlias = false;
this->previous = NULL;
this->protection = Prot(Prot::undefined);
this->inuse = 0;
@@ -538,13 +541,46 @@ TemplateDeclaration::TemplateDeclaration(Loc loc, Identifier *id,
// Compute in advance for Ddoc's use
// Bugzilla 11153: ident could be NULL if parsing fails.
- if (members && ident)
+ if (!members || !ident)
+ return;
+
+ Dsymbol *s;
+ if (!Dsymbol::oneMembers(members, &s, ident) || !s)
+ return;
+
+ onemember = s;
+ s->parent = this;
+
+ /* Set isTrivialAliasSeq if this fits the pattern:
+ * template AliasSeq(T...) { alias AliasSeq = T; }
+ * or set isTrivialAlias if this fits the pattern:
+ * template Alias(T) { alias Alias = qualifiers(T); }
+ */
+ if (!(parameters && parameters->length == 1))
+ return;
+
+ AliasDeclaration *ad = s->isAliasDeclaration();
+ if (!ad || !ad->type)
+ return;
+
+ TypeIdentifier *ti = ad->type->isTypeIdentifier();
+ if (!ti || ti->idents.length != 0)
+ return;
+
+ if (TemplateTupleParameter *ttp = (*parameters)[0]->isTemplateTupleParameter())
{
- Dsymbol *s;
- if (Dsymbol::oneMembers(members, &s, ident) && s)
+ if (ti->ident == ttp->ident && ti->mod == 0)
+ {
+ //printf("found isAliasSeq %s %s\n", s->toChars(), ad->type->toChars());
+ isTrivialAliasSeq = true;
+ }
+ }
+ else if (TemplateTypeParameter *ttp = (*parameters)[0]->isTemplateTypeParameter())
+ {
+ if (ti->ident == ttp->ident)
{
- onemember = s;
- s->parent = this;
+ //printf("found isAlias %s %s\n", s->toChars(), ad->type->toChars());
+ isTrivialAlias = true;
}
}
}
@@ -6223,6 +6259,14 @@ bool TemplateInstance::semanticTiargs(Loc loc, Scope *sc, Objects *tiargs, int f
sa = ((DotTemplateExp *)ea)->td;
goto Ldsym;
}
+ if (ea->op == TOKdot)
+ {
+ if (ScopeExp *se = ((DotExp *)ea)->e2->isScopeExp())
+ {
+ sa = se->sds;
+ goto Ldsym;
+ }
+ }
}
else if (sa)
{
@@ -6770,8 +6814,7 @@ Dsymbols *TemplateInstance::appendToModuleMember()
{
Module *mi = minst; // instantiated -> inserted module
- if (global.params.useUnitTests ||
- global.params.debuglevel)
+ if (global.params.useUnitTests)
{
// Turn all non-root instances to speculative
if (mi && !mi->isRoot())
diff --git a/gcc/d/dmd/hdrgen.c b/gcc/d/dmd/hdrgen.c
index 9eba88f..9397b1e 100644
--- a/gcc/d/dmd/hdrgen.c
+++ b/gcc/d/dmd/hdrgen.c
@@ -1714,6 +1714,10 @@ public:
objectToBuffer(arg);
}
}
+ else if (Parameter *p = isParameter(oarg))
+ {
+ p->accept(this);
+ }
else if (!oarg)
{
buf->writestring("NULL");
diff --git a/gcc/d/dmd/mtype.c b/gcc/d/dmd/mtype.c
index 1c73f50..9ef8ab4 100644
--- a/gcc/d/dmd/mtype.c
+++ b/gcc/d/dmd/mtype.c
@@ -7039,7 +7039,10 @@ Expression *TypeStruct::dotExp(Scope *sc, Expression *e, Identifier *ident, int
*/
e = expressionSemantic(e, sc); // do this before turning on noaccesscheck
- sym->size(e->loc); // do semantic of type
+ if (!sym->determineFields())
+ {
+ error(e->loc, "unable to determine fields of `%s` because of forward references", toChars());
+ }
Expression *e0 = NULL;
Expression *ev = e->op == TOKtype ? NULL : e;
@@ -7373,7 +7376,9 @@ bool TypeStruct::hasPointers()
// Probably should cache this information in sym rather than recompute
StructDeclaration *s = sym;
- sym->size(Loc()); // give error for forward references
+ if (sym->members && !sym->determineFields() && sym->type != Type::terror)
+ error(sym->loc, "no size because of forward references");
+
for (size_t i = 0; i < s->fields.length; i++)
{
Declaration *d = s->fields[i];
diff --git a/gcc/d/dmd/template.h b/gcc/d/dmd/template.h
index fb842ac..086ec72 100644
--- a/gcc/d/dmd/template.h
+++ b/gcc/d/dmd/template.h
@@ -77,6 +77,8 @@ public:
bool literal; // this template declaration is a literal
bool ismixin; // template declaration is only to be used as a mixin
bool isstatic; // this is static template declaration
+ bool isTrivialAliasSeq; // matches `template AliasSeq(T...) { alias AliasSeq = T; }
+ bool isTrivialAlias; // matches `template Alias(T) { alias Alias = T; }
Prot protection;
int inuse; // for recursive expansion detection
diff --git a/gcc/d/dmd/traits.c b/gcc/d/dmd/traits.c
index 99b5457..5a9f58b 100644
--- a/gcc/d/dmd/traits.c
+++ b/gcc/d/dmd/traits.c
@@ -1560,6 +1560,13 @@ Expression *semanticTraits(TraitsExp *e, Scope *sc)
s = imp->mod;
}
+ // https://issues.dlang.org/show_bug.cgi?id=16044
+ if (Package *p = s->isPackage())
+ {
+ if (Module *pm = p->isPackageMod())
+ s = pm;
+ }
+
ScopeDsymbol *sds = s->isScopeDsymbol();
if (!sds || sds->isTemplateDeclaration())
{
@@ -1587,6 +1594,11 @@ Expression *semanticTraits(TraitsExp *e, Scope *sc)
}
}
+ // https://issues.dlang.org/show_bug.cgi?id=20915
+ // skip version and debug identifiers
+ if (sm->isVersionSymbol() || sm->isDebugSymbol())
+ return 0;
+
//printf("\t[%i] %s %s\n", i, sm->kind(), sm->toChars());
if (sm->ident)
{
diff --git a/gcc/d/dmd/typesem.c b/gcc/d/dmd/typesem.c
index 670144d..31e93c2 100644
--- a/gcc/d/dmd/typesem.c
+++ b/gcc/d/dmd/typesem.c
@@ -797,7 +797,7 @@ Type *typeSemantic(Type *type, const Loc &loc, Scope *sc)
if (tf->isreturn && !tf->isref && !tf->next->hasPointers())
{
- ::error(loc, "function type `%s` has `return` but does not return any indirections", tf->toChars());
+ tf->isreturn = false;
}
}
@@ -872,7 +872,7 @@ Type *typeSemantic(Type *type, const Loc &loc, Scope *sc)
if (0 && !tf->isref)
{
StorageClass stc = fparam->storageClass & (STCref | STCout);
- ::error(loc, "parameter %s is `return %s` but function does not return by ref",
+ ::error(loc, "parameter `%s` is `return %s` but function does not return by `ref`",
fparam->ident ? fparam->ident->toChars() : "",
stcToChars(stc));
errors = true;
@@ -886,9 +886,7 @@ Type *typeSemantic(Type *type, const Loc &loc, Scope *sc)
}
else if (!tf->isref && tf->next && !tf->next->hasPointers())
{
- ::error(loc, "parameter %s is `return` but function does not return any indirections",
- fparam->ident ? fparam->ident->toChars() : "");
- errors = true;
+ fparam->storageClass &= STCreturn; // https://issues.dlang.org/show_bug.cgi?id=18963
}
}
}
diff --git a/gcc/d/dmd/version.h b/gcc/d/dmd/version.h
index 9e7fd5e..33811ee 100644
--- a/gcc/d/dmd/version.h
+++ b/gcc/d/dmd/version.h
@@ -24,6 +24,7 @@ public:
const char *toChars();
void addMember(Scope *sc, ScopeDsymbol *sds);
const char *kind() const;
+ DebugSymbol *isDebugSymbol() { return this; }
void accept(Visitor *v) { v->visit(this); }
};
@@ -39,5 +40,6 @@ public:
const char *toChars();
void addMember(Scope *sc, ScopeDsymbol *sds);
const char *kind() const;
+ VersionSymbol *isVersionSymbol() { return this; }
void accept(Visitor *v) { v->visit(this); }
};