diff options
author | Iain Buclaw <ibuclaw@gdcproject.org> | 2020-08-25 22:13:52 +0200 |
---|---|---|
committer | Iain Buclaw <ibuclaw@gdcproject.org> | 2020-08-26 10:03:56 +0200 |
commit | f0a0a84cd9a75052114066a15beebeee8c2cf8ab (patch) | |
tree | cab389d5cbf87ed0d467a59f344c83056632070c /gcc/d | |
parent | 87e36d9baf41a8642ca8687e846764e0828a088b (diff) | |
download | gcc-f0a0a84cd9a75052114066a15beebeee8c2cf8ab.zip gcc-f0a0a84cd9a75052114066a15beebeee8c2cf8ab.tar.gz gcc-f0a0a84cd9a75052114066a15beebeee8c2cf8ab.tar.bz2 |
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
Diffstat (limited to 'gcc/d')
-rw-r--r-- | gcc/d/dmd/MERGE | 2 | ||||
-rw-r--r-- | gcc/d/dmd/func.c | 82 | ||||
-rw-r--r-- | gcc/d/dmd/statementsem.c | 4 |
3 files changed, 35 insertions, 53 deletions
diff --git a/gcc/d/dmd/MERGE b/gcc/d/dmd/MERGE index 276406c..4676645 100644 --- a/gcc/d/dmd/MERGE +++ b/gcc/d/dmd/MERGE @@ -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. diff --git a/gcc/d/dmd/func.c b/gcc/d/dmd/func.c index f8e9601..dbc5fa6 100644 --- a/gcc/d/dmd/func.c +++ b/gcc/d/dmd/func.c @@ -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) - { - 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; - } + // 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; } - 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; } diff --git a/gcc/d/dmd/statementsem.c b/gcc/d/dmd/statementsem.c index 9049347..42f885d 100644 --- a/gcc/d/dmd/statementsem.c +++ b/gcc/d/dmd/statementsem.c @@ -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) |