d: Merge upstream dmd e49192807

1. Removes prelude assert for constructors and destructors.  To trigger
these asserts one needed to construct or destruct an aggregate at the
null memory location.  This would crash upon any data member access,
which is required for a constructor or destructor to do anything useful.

2. Disables bounds checking in foreach statements, when the array is
either a static or dynamic array.  If we trust the array `.length' to
be correct, then all elements are between `[0 .. length]', and can't
can't be out of bounds.

Reviewed-on: https://github.com/dlang/dmd/pull/11623

gcc/d/ChangeLog:

	* dmd/MERGE: Merge upstream dmd e49192807
This commit is contained in:
Iain Buclaw 2020-08-25 22:13:52 +02:00
parent 87e36d9baf
commit f0a0a84cd9
3 changed files with 35 additions and 53 deletions

View file

@ -1,4 +1,4 @@
fe5f388d8e5d97dccaa4ef1349f931c36a2cbc46
e49192807967c6f11252683a731c5a0159ef36da
The first line of this file holds the git revision number of the last
merge done from the dlang/dmd repository.

View file

@ -30,7 +30,7 @@
#include "visitor.h"
#include "objc.h"
Expression *addInvariant(Loc loc, Scope *sc, AggregateDeclaration *ad, VarDeclaration *vthis, bool direct);
Expression *addInvariant(AggregateDeclaration *ad, VarDeclaration *vthis);
bool checkReturnEscape(Scope *sc, Expression *e, bool gag);
bool checkReturnEscapeRef(Scope *sc, Expression *e, bool gag);
bool checkNestedRef(Dsymbol *s, Dsymbol *p);
@ -1648,7 +1648,7 @@ void FuncDeclaration::semantic3(Scope *sc)
Statement *fpreinv = NULL;
if (addPreInvariant())
{
Expression *e = addInvariant(loc, sc, ad, vthis, isDtorDeclaration() != NULL);
Expression *e = addInvariant(ad, vthis);
if (e)
fpreinv = new ExpStatement(Loc(), e);
}
@ -1657,7 +1657,7 @@ void FuncDeclaration::semantic3(Scope *sc)
Statement *fpostinv = NULL;
if (addPostInvariant())
{
Expression *e = addInvariant(loc, sc, ad, vthis, isCtorDeclaration() != NULL);
Expression *e = addInvariant(ad, vthis);
if (e)
fpostinv = new ExpStatement(Loc(), e);
}
@ -4154,67 +4154,47 @@ bool FuncDeclaration::addPostInvariant()
* Input:
* ad aggregate with the invariant
* vthis variable with 'this'
* direct call invariant directly
* Returns:
* void expression that calls the invariant
*/
Expression *addInvariant(Loc loc, Scope *sc, AggregateDeclaration *ad, VarDeclaration *vthis, bool direct)
Expression *addInvariant(AggregateDeclaration *ad, VarDeclaration *vthis)
{
Expression *e = NULL;
if (direct)
// Call invariant directly only if it exists
FuncDeclaration *inv = ad->inv;
ClassDeclaration *cd = ad->isClassDeclaration();
while (!inv && cd)
{
// Call invariant directly only if it exists
FuncDeclaration *inv = ad->inv;
ClassDeclaration *cd = ad->isClassDeclaration();
while (!inv && cd)
{
cd = cd->baseClass;
if (!cd)
break;
inv = cd->inv;
}
if (inv)
{
#if 1
// Workaround for bugzilla 13394: For the correct mangling,
// run attribute inference on inv if needed.
inv->functionSemantic();
#endif
//e = new DsymbolExp(Loc(), inv);
//e = new CallExp(Loc(), e);
//e = e->semantic(sc2);
/* Bugzilla 13113: Currently virtual invariant calls completely
* bypass attribute enforcement.
* Change the behavior of pre-invariant call by following it.
*/
e = new ThisExp(Loc());
e->type = vthis->type;
e = new DotVarExp(Loc(), e, inv, false);
e->type = inv->type;
e = new CallExp(Loc(), e);
e->type = Type::tvoid;
}
cd = cd->baseClass;
if (!cd)
break;
inv = cd->inv;
}
else
if (inv)
{
#if 1
// Workaround for bugzilla 13394: For the correct mangling,
// run attribute inference on inv if needed.
if (ad->isStructDeclaration() && ad->inv)
ad->inv->functionSemantic();
inv->functionSemantic();
#endif
// Call invariant virtually
Expression *v = new ThisExp(Loc());
v->type = vthis->type;
if (ad->isStructDeclaration())
v = v->addressOf();
e = new StringExp(Loc(), const_cast<char *>("null this"));
e = new AssertExp(loc, v, e);
e = semantic(e, sc);
//e = new DsymbolExp(Loc(), inv);
//e = new CallExp(Loc(), e);
//e = e->semantic(sc2);
/* https://issues.dlang.org/show_bug.cgi?id=13113
* Currently virtual invariant calls completely
* bypass attribute enforcement.
* Change the behavior of pre-invariant call by following it.
*/
e = new ThisExp(Loc());
e->type = vthis->type;
e = new DotVarExp(Loc(), e, inv, false);
e->type = inv->type;
e = new CallExp(Loc(), e);
e->type = Type::tvoid;
}
return e;
}

View file

@ -1188,7 +1188,9 @@ public:
}
// T value = tmp[key];
fs->value->_init = new ExpInitializer(loc, new IndexExp(loc, new VarExp(loc, tmp), new VarExp(loc, fs->key)));
IndexExp *indexExp = new IndexExp(loc, new VarExp(loc, tmp), new VarExp(loc, fs->key));
indexExp->indexIsInBounds = true; // disabling bounds checking in foreach statements.
fs->value->_init = new ExpInitializer(loc, indexExp);
Statement *ds = new ExpStatement(loc, fs->value);
if (dim == 2)