Skip to content

Commit

Permalink
Merge pull request #3851 from 9rnsr/2.066
Browse files Browse the repository at this point in the history
Cherry-picking commits from master to 2.066 branch (for RC2)
  • Loading branch information
AndrewEdwards committed Aug 8, 2014
2 parents 150ce77 + a3b6ed6 commit 3894b77
Show file tree
Hide file tree
Showing 18 changed files with 169 additions and 43 deletions.
43 changes: 36 additions & 7 deletions src/backend/gother.c
Expand Up @@ -921,9 +921,9 @@ void copyprop()
/* and the d=b copy elem now reaches the end */
/* of the block (the d=a elem didn't). */
}
if (recalc)
goto Lagain;
}
if (recalc)
goto Lagain;
}

/*****************************
Expand All @@ -940,6 +940,8 @@ STATIC void cpwalk(register elem *n,vec_t IN)

assert(n && IN);
/*chkvecdim(exptop,0);*/
if (recalc)
return;
op = n->Eoper;
if (op == OPcolon || op == OPcolon2)
{
Expand Down Expand Up @@ -1086,17 +1088,44 @@ STATIC void cpwalk(register elem *n,vec_t IN)
}
if (foundelem) /* if we can do the copy prop */
{
cmes3("Copyprop, from '%s' to '%s'\n",
(v->Sident) ? (char *)v->Sident : "temp",
(f->Sident) ? (char *)f->Sident : "temp");

#ifdef DEBUG
if (debugc)
{
printf("Copyprop, from '%s'(%d) to '%s'(%d)\n",
(v->Sident) ? (char *)v->Sident : "temp", v->Ssymnum,
(f->Sident) ? (char *)f->Sident : "temp", f->Ssymnum);
}
#endif
type *nt = n->ET;
el_copy(n,foundelem->E2);
n->Ety = ty; // retain original type
n->ET = nt;

/* original => rewrite
* v = f
* g = v => g = f
* f = x
* d = g => d = f !!error
* Therefore, if g appears as an rvalue in expnod[], then recalc
*/
for (size_t i = 1; i < exptop; ++i)
{
if (expnod[i]->E2 == n)
{
symbol *g = expnod[i]->E1->EV.sp.Vsym;
for (size_t j = 1; j < exptop; ++j)
{
if (expnod[j]->E2->EV.sp.Vsym == g)
{
++recalc;
break;
}
}
break;
}
}

changes++;
recalc++;
}
//else dbg_printf("not found\n");
noprop:
Expand Down
12 changes: 10 additions & 2 deletions src/expression.c
Expand Up @@ -3572,8 +3572,11 @@ bool NullExp::equals(RootObject *o)
if (o && o->dyncast() == DYNCAST_EXPRESSION)
{
Expression *e = (Expression *)o;
if (e->op == TOKnull)
if (e->op == TOKnull &&
type->equals(e->type))
{
return true;
}
}
return false;
}
Expand Down Expand Up @@ -4022,6 +4025,11 @@ bool ArrayLiteralExp::equals(RootObject *o)
ArrayLiteralExp *ae = (ArrayLiteralExp *)o;
if (elements->dim != ae->elements->dim)
return false;
if (elements->dim == 0 &&
!type->equals(ae->type))
{
return false;
}
for (size_t i = 0; i < elements->dim; i++)
{
Expression *e1 = (*elements)[i];
Expand Down Expand Up @@ -4273,7 +4281,7 @@ bool StructLiteralExp::equals(RootObject *o)
((Expression *)o)->op == TOKstructliteral)
{
StructLiteralExp *se = (StructLiteralExp *)o;
if (sd != se->sd)
if (!type->equals(se->type))
return false;
if (elements->dim != se->elements->dim)
return false;
Expand Down
6 changes: 6 additions & 0 deletions src/func.c
Expand Up @@ -4492,6 +4492,12 @@ const char *FuncLiteralDeclaration::kind()

void FuncLiteralDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
{
if (type->ty == Terror)
{
buf->writestring("__error");
return;
}

if (tok != TOKreserved)
{
buf->writestring(kind());
Expand Down
2 changes: 1 addition & 1 deletion src/module.c
Expand Up @@ -616,7 +616,7 @@ void Module::parse()
pkg->mod = this;
}
else
error(pkg->loc, "from file %s conflicts with package name %s",
error(md ? md->loc : loc, "from file %s conflicts with package name %s",
srcname, pkg->toChars());
}
else
Expand Down
6 changes: 4 additions & 2 deletions src/mtype.c
Expand Up @@ -9609,11 +9609,13 @@ int Parameter::foreach(Parameters *args, Parameter::ForeachDg dg, void *ctx, siz
size_t n = pn ? *pn : 0; // take over index
int result = 0;
for (size_t i = 0; i < args->dim; i++)
{ Parameter *arg = (*args)[i];
{
Parameter *arg = (*args)[i];
Type *t = arg->type->toBasetype();

if (t->ty == Ttuple)
{ TypeTuple *tu = (TypeTuple *)t;
{
TypeTuple *tu = (TypeTuple *)t;
result = foreach(tu->arguments, dg, ctx, &n);
}
else
Expand Down
39 changes: 14 additions & 25 deletions src/template.c
Expand Up @@ -292,21 +292,20 @@ int match(RootObject *o1, RootObject *o2)
{
//printf("t1 = %s\n", t1->toChars());
//printf("t2 = %s\n", t2->toChars());
if (!t2 || !t1->equals(t2))
if (!t2)
goto Lnomatch;
if (!t1->equals(t2))
goto Lnomatch;
}
else if (e1)
{
#if 0
if (e1 && e2)
{
printf("match %d\n", e1->equals(e2));
printf("\te1 = %p %s %s %s\n", e1, e1->type->toChars(), Token::toChars(e1->op), e1->toChars());
printf("\te2 = %p %s %s %s\n", e2, e2->type->toChars(), Token::toChars(e2->op), e2->toChars());
}
#endif
if (!e2)
goto Lnomatch;
#if 0
printf("match %d\n", e1->equals(e2));
printf("\te1 = %p %s %s %s\n", e1, e1->type->toChars(), Token::toChars(e1->op), e1->toChars());
printf("\te2 = %p %s %s %s\n", e2, e2->type->toChars(), Token::toChars(e2->op), e2->toChars());
#endif
if (!e1->equals(e2))
goto Lnomatch;
}
Expand Down Expand Up @@ -8076,24 +8075,15 @@ void TemplateMixin::semantic(Scope *sc)
#endif
if (semanticRun != PASSinit)
{
// This for when a class/struct contains mixin members, and
// is done over because of forward references
if (parent && toParent()->isAggregateDeclaration())
{
if (sc->parent != parent)
return;
semanticRun = PASSsemantic; // do over
}
else
{
// When a class/struct contains mixin members, and is done over
// because of forward references, never reach here so semanticRun
// has been reset to PASSinit.
#if LOG
printf("\tsemantic done\n");
printf("\tsemantic done\n");
#endif
return;
}
return;
}
if (semanticRun == PASSinit)
semanticRun = PASSsemantic;
semanticRun = PASSsemantic;
#if LOG
printf("\tdo semantic\n");
#endif
Expand All @@ -8106,7 +8096,6 @@ void TemplateMixin::semantic(Scope *sc)
scope = NULL;
}


/* Run semantic on each argument, place results in tiargs[],
* then find best match template with tiargs
*/
Expand Down
1 change: 0 additions & 1 deletion src/todt.c
Expand Up @@ -188,7 +188,6 @@ dt_t *Initializer_toDt(Initializer *init)

InitToDt v;
init->accept(&v);
assert(v.result);
return v.result;
}

Expand Down
5 changes: 5 additions & 0 deletions test/compilable/ice13245.d
@@ -0,0 +1,5 @@
// REQUIRED_ARGS: -o-
// PERMUTE_ARGS:

template T(alias f) {}
static assert(!is(T!( (int x){ return invalid; } )));
2 changes: 1 addition & 1 deletion test/d_do_test.d
Expand Up @@ -322,7 +322,7 @@ string unifyNewLine(string str)

string unifyDirSep(string str, string sep)
{
return std.regex.replace(str, regex(`(?<=\w\w*)/(?=\w[\w/]*\.di?\b)`, "g"), sep);
return std.regex.replace(str, regex(`(?<=[-\w][-\w]*)/(?=[-\w][-\w/]*\.di?\b)`, "g"), sep);
}
unittest
{
Expand Down
1 change: 1 addition & 0 deletions test/fail_compilation/extra-files/bar11453.d
@@ -0,0 +1 @@
module foo11453.bar11453;
1 change: 1 addition & 0 deletions test/fail_compilation/extra-files/foo11453.d
@@ -0,0 +1 @@
module foo11453;
10 changes: 10 additions & 0 deletions test/fail_compilation/fail11453a.d
@@ -0,0 +1,10 @@
// REQUIRED_ARGS: -Ifail_compilation/extra-files
// EXTRA_SOURCES: extra-files/foo11453.d extra-files/bar11453.d
/*
TEST_OUTPUT
---
fail_compilation/extra-files/bar11453.d(1): Error: package name 'foo11453' conflicts with usage as a module name in file fail_compilation/extra-files/foo11453.d
---
*/

void main() {}
10 changes: 10 additions & 0 deletions test/fail_compilation/fail11453b.d
@@ -0,0 +1,10 @@
// REQUIRED_ARGS: -Ifail_compilation/extra-files
// EXTRA_SOURCES: extra-files/bar11453.d extra-files/foo11453.d
/*
TEST_OUTPUT
---
fail_compilation/extra-files/foo11453.d(1): Error: module foo11453 from file fail_compilation/extra-files/foo11453.d conflicts with package name foo11453
---
*/

void main() {}
14 changes: 14 additions & 0 deletions test/fail_compilation/ice13225.d
@@ -0,0 +1,14 @@
/*
TEST_OUTPUT:
---
fail_compilation/ice13225.d(13): Error: undefined identifier undefined
---
*/

mixin template M(T) {}

struct S
{
mixin M!((typeof(this)) => 0);
mixin M!(() => undefined);
}
8 changes: 8 additions & 0 deletions test/fail_compilation/ice13259.d
@@ -0,0 +1,8 @@
/*
TEST_OUTPUT:
---
fail_compilation/ice13259.d(8): Error: non-constant nested delegate literal expression __dgliteral3
---
*/

auto dg = delegate {};
8 changes: 4 additions & 4 deletions test/fail_compilation/test64.d
@@ -1,19 +1,19 @@
/*
TEST_OUTPUT:
---
Error: module imports from file fail_compilation/imports/test64a.d conflicts with package name imports
fail_compilation/imports/test64a.d(1): Error: module imports from file fail_compilation/imports/test64a.d conflicts with package name imports
---
*/

// PERMUTE_ARGS:

import std.stdio;
//import std.stdio;

import imports.test64a;

int main(char[][] args)
int main(string[] args)
{
writefln(file1);
//writefln(file1);
return 0;
}

27 changes: 27 additions & 0 deletions test/runnable/template9.d
Expand Up @@ -3854,6 +3854,33 @@ void test13223()
//static assert(is(typeof(f5(null)) == void[]));
}

/******************************************/
// 13252

alias TypeTuple13252(T...) = T;

static assert(is(typeof(TypeTuple13252!(cast(int )1)[0]) == int ));
static assert(is(typeof(TypeTuple13252!(cast(long)1)[0]) == long));

static assert(is(typeof(TypeTuple13252!(cast(float )3.14)[0]) == float ));
static assert(is(typeof(TypeTuple13252!(cast(double)3.14)[0]) == double));

static assert(is(typeof(TypeTuple13252!(cast(cfloat )(1 + 2i))[0]) == cfloat ));
static assert(is(typeof(TypeTuple13252!(cast(cdouble)(1 + 2i))[0]) == cdouble));

static assert(is(typeof(TypeTuple13252!(cast(string )null)[0]) == string ));
static assert(is(typeof(TypeTuple13252!(cast(string[])null)[0]) == string[])); // OK <- NG

static assert(is(typeof(TypeTuple13252!(cast(wstring)"abc")[0]) == wstring));
static assert(is(typeof(TypeTuple13252!(cast(dstring)"abc")[0]) == dstring));

static assert(is(typeof(TypeTuple13252!(cast(int[] )[])[0]) == int[] ));
static assert(is(typeof(TypeTuple13252!(cast(long[])[])[0]) == long[])); // OK <- NG

struct S13252 { }
static assert(is(typeof(TypeTuple13252!(const S13252())[0]) == const(S13252)));
static assert(is(typeof(TypeTuple13252!(immutable S13252())[0]) == immutable(S13252))); // OK <- NG

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

int main()
Expand Down
17 changes: 17 additions & 0 deletions test/runnable/test23.d
Expand Up @@ -1462,6 +1462,22 @@ void test71()

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

size_t getLength(int[] arr) { return arr.length; }

void test13237()
{
int[] arr = [0];
immutable size_t len = getLength(arr);

arr.length--;

assert(len == 1); // ok
if (len) { auto l = len; }
assert(len == 1); // len cannot be changed, but produces Assertion failure with "-O -inline"
}

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

void main()
{
test1();
Expand Down Expand Up @@ -1528,6 +1544,7 @@ void main()
test69();
test70();
test71();
test13237();

printf("Success\n");
}

0 comments on commit 3894b77

Please sign in to comment.