Skip to content

Commit

Permalink
Merge pull request #3765 from AndrewEdwards/2.066
Browse files Browse the repository at this point in the history
Regression fixes for 2.066.0-b4
  • Loading branch information
9rnsr committed Jul 15, 2014
2 parents 2b79556 + e7c1ba5 commit 41c7d68
Show file tree
Hide file tree
Showing 6 changed files with 185 additions and 17 deletions.
18 changes: 11 additions & 7 deletions src/lexer.c
Expand Up @@ -1875,6 +1875,7 @@ TOK Lexer::number(Token *t)
uinteger_t n = 0; // unsigned >=64 bit integer type
int d;
bool err = false;
bool overflow = false;

c = *p;
if (c == '0')
Expand Down Expand Up @@ -2007,25 +2008,28 @@ TOK Lexer::number(Token *t)
}

uinteger_t n2 = n * base;
if ((n2 / base != n || n2 + d < n) && !err)
if ((n2 / base != n || n2 + d < n))
{
error("integer overflow");
err = true;
overflow = true;
}
n = n2 + d;

// if n needs more than 64 bits
if (sizeof(n) > 8 &&
n > 0xFFFFFFFFFFFFFFFFULL &&
!err)
n > 0xFFFFFFFFFFFFFFFFULL)
{
error("integer overflow");
err = true;
overflow = true;
}
}

Ldone:

if (overflow && !err)
{
error("integer overflow");
err = true;
}

enum FLAGS
{
FLAGS_none = 0,
Expand Down
33 changes: 33 additions & 0 deletions src/mtype.c
Expand Up @@ -4809,6 +4809,39 @@ printf("index->ito->ito = x%x\n", index->ito->ito);
*/
}
}
else if (tbase->ty == Tclass && !((TypeClass *)tbase)->sym->isInterfaceDeclaration())
{
ClassDeclaration *cd = ((TypeClass *)tbase)->sym;
if (cd->scope)
cd->semantic(NULL);

if (!ClassDeclaration::object)
{
error(Loc(), "missing or corrupt object.d");
fatal();
}

static FuncDeclaration *feq = NULL;
static FuncDeclaration *fcmp = NULL;
static FuncDeclaration *fhash = NULL;
if (!feq) feq = search_function(ClassDeclaration::object, Id::eq)->isFuncDeclaration();
if (!fcmp) fcmp = search_function(ClassDeclaration::object, Id::cmp)->isFuncDeclaration();
if (!fhash) fhash = search_function(ClassDeclaration::object, Id::tohash)->isFuncDeclaration();
assert(fcmp && feq && fhash);

if (feq ->vtblIndex < cd->vtbl.dim && cd->vtbl[feq ->vtblIndex] == feq)
{
#if 1
if (fcmp->vtblIndex < cd->vtbl.dim && cd->vtbl[fcmp->vtblIndex] != fcmp)
{
const char *s = (index->toBasetype()->ty != Tclass) ? "bottom of " : "";
error(loc, "%sAA key type %s now requires equality rather than comparison",
s, cd->toChars());
errorSupplemental(loc, "Please override Object.opEquals and toHash.");
}
#endif
}
}
next = next->semantic(loc,sc)->merge2();
transitive();

Expand Down
55 changes: 45 additions & 10 deletions src/s2ir.c
Expand Up @@ -386,22 +386,19 @@ class S2irVisitor : public Visitor
return;
block *b = blx->curblock;
incUsage(irs, s->loc);
b->appendSucc(bdest);

if (b->Btry != bdest->Btry)
// Check that bdest is in an enclosing try block
for (block *bt = b->Btry; bt != bdest->Btry; bt = bt->Btry)
{
// Check that bdest is in an enclosing try block
for (block *bt = b->Btry; bt != bdest->Btry; bt = bt->Btry)
if (!bt)
{
if (!bt)
{
//printf("b->Btry = %p, bdest->Btry = %p\n", b->Btry, bdest->Btry);
s->error("cannot goto into try block");
break;
}
//printf("b->Btry = %p, bdest->Btry = %p\n", b->Btry, bdest->Btry);
s->error("cannot goto into try block");
break;
}
}

b->appendSucc(bdest);
block_next(blx,BCgoto,NULL);
}

Expand Down Expand Up @@ -1131,6 +1128,44 @@ class S2irVisitor : public Visitor

finallyblock->appendSucc(blx->curblock);
retblock->appendSucc(blx->curblock);

/* The BCfinally..BC_ret blocks form a function that gets called from stack unwinding.
* The successors to BC_ret blocks are both the next outer BCfinally and the destination
* after the unwinding is complete.
*/
for (block *b = tryblock; b != finallyblock; b = b->Bnext)
{
block *btry = b->Btry;

if (b->BC == BCgoto && b->numSucc() == 1)
{
block *bdest = b->nthSucc(0);
if (btry && bdest->Btry != btry)
{
//printf("test1 b %p b->Btry %p bdest %p bdest->Btry %p\n", b, btry, bdest, bdest->Btry);
block *bfinally = btry->nthSucc(1);
if (bfinally == finallyblock)
b->appendSucc(finallyblock);
}
}

// If the goto exits a try block, then the finally block is also a successor
if (b->BC == BCgoto && b->numSucc() == 2) // if goto exited a tryblock
{
block *bdest = b->nthSucc(0);

// If the last finally block executed by the goto
if (bdest->Btry == tryblock->Btry)
// The finally block will exit and return to the destination block
retblock->appendSucc(bdest);
}

if (b->BC == BC_ret && b->Btry == tryblock)
{
// b is nested inside this TryFinally, and so this finally will be called next
b->appendSucc(finallyblock);
}
}
}

/****************************************
Expand Down
41 changes: 41 additions & 0 deletions test/fail_compilation/diag13074.d
Expand Up @@ -32,3 +32,44 @@ void main()
arr[s3] = true;
arr[s4] = true;
}

/*
TEST_OUTPUT:
---
fail_compilation/diag13074.d(70): Error: AA key type C now requires equality rather than comparison
fail_compilation/diag13074.d(70): Please override Object.opEquals and toHash.
---
*/
class C
{
int x;
int y;
this(int x, int y)
{
this.x = x; this.y = y;
}

override int opCmp(Object other)
{
if (auto o = cast(C)other)
return x < o.x ? -1 : x > o.x ? 1 : 0;
return -1;
}
override hash_t toHash() const
{
return x;
}
}

void test13114()
{
const c1 = new C(1,1);
const c2 = new C(1,2);
const c3 = new C(2,1);
const c4 = new C(2,2);
bool[const(C)] arr;
arr[c1] = true;
arr[c2] = true;
arr[c3] = true;
arr[c4] = true;
}
51 changes: 51 additions & 0 deletions test/runnable/eh.d
Expand Up @@ -702,6 +702,56 @@ void test10964()

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

alias Action = void delegate();

class A10
{
invariant()
{
}

public Action foo(Action a)
{
synchronized
{
B10 elements = new B10;
Action[] actions = [a];

elements.bar(actions);

if (actions.length > 1)
elements.bar(actions);
return actions[0];
}
return null;
}
}

class B10
{
public bool bar(ref Action[])
{
return false;
}
}

class D10
{
void baz()
{
}
}

void test12989()
{
auto a = new A10;
auto d = new D10;

assert(a.foo(&d.baz) == &d.baz);
}

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

int main()
{
printf("start\n");
Expand All @@ -722,6 +772,7 @@ int main()
test8();
test9();
test10964();
test12989();

printf("finish\n");
return 0;
Expand Down
4 changes: 4 additions & 0 deletions test/runnable/lexer.d
Expand Up @@ -77,6 +77,10 @@ debug(9223372036854775807){}

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

enum e13102=184467440737095516153.6L;

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

int main()
{
test6();
Expand Down

0 comments on commit 41c7d68

Please sign in to comment.