aboutsummaryrefslogtreecommitdiff
path: root/gcc/d
diff options
context:
space:
mode:
authorIain Buclaw <ibuclaw@gcc.gnu.org>2019-06-16 07:50:07 +0000
committerIain Buclaw <ibuclaw@gcc.gnu.org>2019-06-16 07:50:07 +0000
commite5d0ba591e28d8be1fb5775fb0418fee04af17d7 (patch)
tree2e9f2bbf419a978098a1a9c4cb3305fd4a402a89 /gcc/d
parent9bf706aae20a891885780c9d419addd5d0bc510d (diff)
downloadgcc-e5d0ba591e28d8be1fb5775fb0418fee04af17d7.zip
gcc-e5d0ba591e28d8be1fb5775fb0418fee04af17d7.tar.gz
gcc-e5d0ba591e28d8be1fb5775fb0418fee04af17d7.tar.bz2
d/dmd: Merge upstream dmd f8e38c001
Fixes bug where foreach(int) doesn't work on BigEndian targets by deprecating the use of index types smaller than a size_t/ptrdiff_t. Reviewed-on: https://github.com/dlang/dmd/pull/10009 From-SVN: r272350
Diffstat (limited to 'gcc/d')
-rw-r--r--gcc/d/dmd/MERGE2
-rw-r--r--gcc/d/dmd/statementsem.c44
2 files changed, 40 insertions, 6 deletions
diff --git a/gcc/d/dmd/MERGE b/gcc/d/dmd/MERGE
index 03005e3..01c8cb0 100644
--- a/gcc/d/dmd/MERGE
+++ b/gcc/d/dmd/MERGE
@@ -1,4 +1,4 @@
-9746504883fc64f3dcec0cd4cacbb7a372d52158
+f8e38c001b9d7bd6586ee5b3dab7f7f199a69be7
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/statementsem.c b/gcc/d/dmd/statementsem.c
index 0dc5e77..167836c 100644
--- a/gcc/d/dmd/statementsem.c
+++ b/gcc/d/dmd/statementsem.c
@@ -773,16 +773,48 @@ public:
goto Lerror2;
}
+ // Finish semantic on all foreach parameter types.
+ for (size_t i = 0; i < dim; i++)
+ {
+ Parameter *p = (*fs->parameters)[i];
+ p->type = p->type->semantic(loc, sc2);
+ p->type = p->type->addStorageClass(p->storageClass);
+ }
+
+ tn = tab->nextOf()->toBasetype();
+
+ if (dim == 2)
+ {
+ Type *tindex = (*fs->parameters)[0]->type;
+ if (!tindex->isintegral())
+ {
+ fs->error("foreach: key cannot be of non-integral type `%s`",
+ tindex->toChars());
+ goto Lerror2;
+ }
+ /* What cases to deprecate implicit conversions for:
+ * 1. foreach aggregate is a dynamic array
+ * 2. foreach body is lowered to _aApply (see special case below).
+ */
+ Type *tv = (*fs->parameters)[1]->type->toBasetype();
+ if ((tab->ty == Tarray ||
+ (tn->ty != tv->ty &&
+ (tn->ty == Tchar || tn->ty == Twchar || tn->ty == Tdchar) &&
+ (tv->ty == Tchar || tv->ty == Twchar || tv->ty == Tdchar))) &&
+ !Type::tsize_t->implicitConvTo(tindex))
+ {
+ fs->deprecation("foreach: loop index implicitly converted from `size_t` to `%s`",
+ tindex->toChars());
+ }
+ }
+
/* Look for special case of parsing char types out of char type
* array.
*/
- tn = tab->nextOf()->toBasetype();
if (tn->ty == Tchar || tn->ty == Twchar || tn->ty == Tdchar)
{
int i = (dim == 1) ? 0 : 1; // index of value
Parameter *p = (*fs->parameters)[i];
- p->type = p->type->semantic(loc, sc2);
- p->type = p->type->addStorageClass(p->storageClass);
tnv = p->type->toBasetype();
if (tnv->ty != tn->ty &&
(tnv->ty == Tchar || tnv->ty == Twchar || tnv->ty == Tdchar))
@@ -809,8 +841,6 @@ public:
{
// Declare parameterss
Parameter *p = (*fs->parameters)[i];
- p->type = p->type->semantic(loc, sc2);
- p->type = p->type->addStorageClass(p->storageClass);
VarDeclaration *var;
if (dim == 2 && i == 0)
@@ -908,6 +938,10 @@ public:
fs->key = new VarDeclaration(loc, Type::tsize_t, idkey, NULL);
fs->key->storage_class |= STCtemp;
}
+ else if (fs->key->type->ty != Tsize_t)
+ {
+ tmp_length = new CastExp(loc, tmp_length, fs->key->type);
+ }
if (fs->op == TOKforeach_reverse)
fs->key->_init = new ExpInitializer(loc, tmp_length);
else