Skip to content

Commit

Permalink
Merge pull request #5154 from WalterBright/fix14782
Browse files Browse the repository at this point in the history
fix Issue 14782 - Internal error: backend/cod1.c
  • Loading branch information
andralex committed Oct 4, 2015
2 parents 43c73c1 + df6a9af commit 6d1f427
Show file tree
Hide file tree
Showing 2 changed files with 139 additions and 88 deletions.
26 changes: 18 additions & 8 deletions src/backend/cgelem.c
Original file line number Diff line number Diff line change
Expand Up @@ -3096,19 +3096,29 @@ elem * elstruct(elem *e, goal_t goal)
return e;
//printf("\tnumbytes = %d\n", (int)type_size(e->ET));

type *t = e->ET;
tym_t tym = ~0;
tym_t ty = tybasic(e->ET->Tty);
tym_t ty = tybasic(t->Tty);

unsigned sz = type_size(t);
//printf("\tsz = %d\n", (int)sz);
if (sz == 16)
{
while (ty == TYarray && t->Tdim == 1)
{
t = t->Tnext;
ty = tybasic(t->Tty);
}
}

type *targ1 = NULL;
type *targ2 = NULL;
if (ty == TYstruct)
{ // If a struct is a wrapper for another type, prefer that other type
targ1 = e->ET->Ttag->Sstruct->Sarg1type;
targ2 = e->ET->Ttag->Sstruct->Sarg2type;
targ1 = t->Ttag->Sstruct->Sarg1type;
targ2 = t->Ttag->Sstruct->Sarg2type;
}

unsigned sz = type_size(e->ET);
//printf("\tsz = %d\n", (int)sz);
//if (targ1) { printf("targ1\n"); type_print(targ1); }
//if (targ2) { printf("targ2\n"); type_print(targ2); }
switch ((int)sz)
Expand Down Expand Up @@ -3185,19 +3195,19 @@ elem * elstruct(elem *e, goal_t goal)
{ // This needs to match what TypeFunction::retStyle() does
if (config.exe == EX_WIN64)
{
//if (e->ET->Ttag->Sstruct->Sflags & STRnotpod)
//if (t->Ttag->Sstruct->Sflags & STRnotpod)
//goto Ldefault;
}
// If a struct is a wrapper for another type, prefer that other type
else if (targ1 && !targ2)
tym = targ1->Tty;
else if (I64 && !targ1 && !targ2)
{ if (e->ET->Ttag->Sstruct->Sflags & STRnotpod)
{ if (t->Ttag->Sstruct->Sflags & STRnotpod)
{
// In-memory only
goto Ldefault;
}
// if (type_size(e->ET) == 16)
// if (type_size(t) == 16)
goto Ldefault;
}
else if (I64 && targ1 && targ2)
Expand Down
201 changes: 121 additions & 80 deletions test/runnable/mars1.d
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ int testswitch()
i = 3;
switch (i)
{
case 0:
case 1:
default:
assert(0);
case 3:
break;
case 0:
case 1:
default:
assert(0);
case 3:
break;
}
return 0;
}
Expand All @@ -36,7 +36,7 @@ void testdo()

do
{
x++;
x++;
} while (x < 10);
printf("x == %d\n", x);
assert(x == 10);
Expand All @@ -49,11 +49,11 @@ void testbreak()
Louter:
for (i = 0; i < 10; i++)
{
for (j = 0; j < 10; j++)
{
if (j == 3)
break Louter;
}
for (j = 0; j < 10; j++)
{
if (j == 3)
break Louter;
}
}

printf("i = %d, j = %d\n", i, j);
Expand All @@ -70,18 +70,18 @@ int foo(string s)
i = 0;
switch (s)
{
case "hello":
i = 1;
break;
case "goodbye":
i = 2;
break;
case "goodb":
i = 3;
break;
default:
i = 10;
break;
case "hello":
i = 1;
break;
case "goodbye":
i = 2;
break;
case "goodb":
i = 3;
break;
default:
i = 10;
break;
}
return i;
}
Expand Down Expand Up @@ -253,35 +253,35 @@ void testulldiv()
{
__gshared ulong[4][] vectors =
[
[10,3,3,1],
[10,1,10,0],
[3,10,0,3],
[10,10,1,0],
[10_000_000_000L, 11_000_000_000L, 0, 10_000_000_000L],
[11_000_000_000L, 10_000_000_000L, 1, 1_000_000_000L],
[11_000_000_000L, 11_000_000_000L, 1, 0],
[10_000_000_000L, 10, 1_000_000_000L, 0],
[0x8000_0000_0000_0000, 0x8000_0000_0000_0000, 1, 0],
[0x8000_0000_0000_0001, 0x8000_0000_0000_0001, 1, 0],
[0x8000_0001_0000_0000, 0x8000_0001_0000_0000, 1, 0],
[0x8000_0001_0000_0000, 0x8000_0000_0000_0000, 1, 0x1_0000_0000],
[0x8000_0001_0000_0000, 0x8000_0000_8000_0000, 1, 0x8000_0000],
[0x8000_0000_0000_0000, 0x7FFF_FFFF_FFFF_FFFF, 1, 1],
[0x8000_0000_0000_0000, 0x8000_0000_0000_0001, 0, 0x8000_0000_0000_0000],
[0x8000_0000_0000_0000, 0x8000_0001_0000_0000, 0, 0x8000_0000_0000_0000],
[10,3,3,1],
[10,1,10,0],
[3,10,0,3],
[10,10,1,0],
[10_000_000_000L, 11_000_000_000L, 0, 10_000_000_000L],
[11_000_000_000L, 10_000_000_000L, 1, 1_000_000_000L],
[11_000_000_000L, 11_000_000_000L, 1, 0],
[10_000_000_000L, 10, 1_000_000_000L, 0],
[0x8000_0000_0000_0000, 0x8000_0000_0000_0000, 1, 0],
[0x8000_0000_0000_0001, 0x8000_0000_0000_0001, 1, 0],
[0x8000_0001_0000_0000, 0x8000_0001_0000_0000, 1, 0],
[0x8000_0001_0000_0000, 0x8000_0000_0000_0000, 1, 0x1_0000_0000],
[0x8000_0001_0000_0000, 0x8000_0000_8000_0000, 1, 0x8000_0000],
[0x8000_0000_0000_0000, 0x7FFF_FFFF_FFFF_FFFF, 1, 1],
[0x8000_0000_0000_0000, 0x8000_0000_0000_0001, 0, 0x8000_0000_0000_0000],
[0x8000_0000_0000_0000, 0x8000_0001_0000_0000, 0, 0x8000_0000_0000_0000],
];

for (size_t i = 0; i < vectors.length; i++)
{
ulong q = vectors[i][0] / vectors[i][1];
if (q != vectors[i][2])
printf("[%d] %lld / %lld = %lld, should be %lld\n",
vectors[i][0], vectors[i][1], q, vectors[i][2]);

ulong r = vectors[i][0] % vectors[i][1];
if (r != vectors[i][3])
printf("[%d] %lld %% %lld = %lld, should be %lld\n",
i, vectors[i][0], vectors[i][1], r, vectors[i][3]);
ulong q = vectors[i][0] / vectors[i][1];
if (q != vectors[i][2])
printf("[%d] %lld / %lld = %lld, should be %lld\n",
vectors[i][0], vectors[i][1], q, vectors[i][2]);

ulong r = vectors[i][0] % vectors[i][1];
if (r != vectors[i][3])
printf("[%d] %lld %% %lld = %lld, should be %lld\n",
i, vectors[i][0], vectors[i][1], r, vectors[i][3]);
}
}

Expand Down Expand Up @@ -438,20 +438,20 @@ void test12095(int k)

bool test3918a( float t, real u )
{
printf("%f\n", u );
return t && u;
printf("%f\n", u );
return t && u;
}

bool test3918b( real t, float u )
{
printf("%f\n", t );
return t && u;
printf("%f\n", t );
return t && u;
}

void test3918()
{
assert(test3918a(float.nan, real.nan));
assert(test3918b(real.nan, float.nan));
assert(test3918a(float.nan, real.nan));
assert(test3918b(real.nan, float.nan));
}

////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -841,17 +841,17 @@ void testnegcom()
int oror1(char c)
{
return ((((((((((cast(int) c <= 32 || cast(int) c == 46) || cast(int) c == 44)
|| cast(int) c == 58) || cast(int) c == 59) || cast(int) c == 60)
|| cast(int) c == 62) || cast(int) c == 34) || cast(int) c == 92)
|| cast(int) c == 39) != 0);
|| cast(int) c == 58) || cast(int) c == 59) || cast(int) c == 60)
|| cast(int) c == 62) || cast(int) c == 34) || cast(int) c == 92)
|| cast(int) c == 39) != 0);
}

int oror2(char c)
{
return ((((((((((c <= 32 || c == 46) || c == 44)
|| c == 58) || c == 59) || c == 60)
|| c == 62) || c == 34) || c == 92)
|| c == 39) != 0);
|| c == 58) || c == 59) || c == 60)
|| c == 62) || c == 34) || c == 92)
|| c == 39) != 0);
}

void testoror()
Expand Down Expand Up @@ -928,32 +928,32 @@ void test13383()
int andand1(int c)
{
return (c > 32 && c != 46 && c != 44
&& c != 58 && c != 59
&& c != 60 && c != 62
&& c != 58 && c != 59
&& c != 60 && c != 62
&& c != 34 && c != 92
&& c != 39) != 0;
&& c != 39) != 0;
}

bool andand2(long c)
{
return (c > 32 && c != 46 && c != 44
&& c != 58 && c != 59
&& c != 60 && c != 62
&& c != 58 && c != 59
&& c != 60 && c != 62
&& c != 34 && c != 92
&& c != 39) != 0;
&& c != 39) != 0;
}

int foox3() { return 1; }

int andand3(uint op)
{
if (foox3() &&
op != 7 &&
op != 3 &&
op != 18 &&
op != 30 &&
foox3())
return 3;
op != 7 &&
op != 3 &&
op != 18 &&
op != 30 &&
foox3())
return 3;
return 4;
}

Expand Down Expand Up @@ -1036,9 +1036,9 @@ void testshrshl()

////////////////////////////////////////////////////////////////////////

struct S1
{
cdouble val;
struct S1
{
cdouble val;
}

void formatTest(S1 s, double re, double im)
Expand Down Expand Up @@ -1253,7 +1253,7 @@ void test12057()


////////////////////////////////////////////////////////////////////////

long modulo24 (long ticks)
{
ticks %= 864000000000;
Expand Down Expand Up @@ -1330,7 +1330,7 @@ int stripLeft(int str, int dc)
{
while (true)
{
int a = str;
int a = str;
int s = a;
str += 1;
if (dc) return s;
Expand All @@ -1340,7 +1340,7 @@ int stripLeft(int str, int dc)
void test14829()
{
if (stripLeft(3, 1) != 3) // fails with -O
assert(0);
assert(0);
}


Expand All @@ -1357,7 +1357,46 @@ void test2()
}

////////////////////////////////////////////////////////////////////////


// 14782


void test14782()
{
static struct Foo
{
long a = 8;
int b = 7;
}

static Foo[1] fun() { Foo[1] a; return a; }

auto result = fun();
assert(result[0].a == 8);
assert(result[0].b == 7);
}

////////////////////////////////////////////////////////////////////////

void test14987()
{
static struct Foo
{
int b = 7;
}
static assert((Foo[4]).sizeof == 16);

static Foo[4] fun() { Foo[4] a; return a; }

auto result = fun();
assert(result[0].b == 7);
assert(result[1].b == 7);
assert(result[2].b == 7);
assert(result[3].b == 7);
}

////////////////////////////////////////////////////////////////////////

int main()
{
testgoto();
Expand Down Expand Up @@ -1402,6 +1441,8 @@ int main()
test14220();
test14829();
test2();
test14782();
test14987();
printf("Success\n");
return 0;
}

0 comments on commit 6d1f427

Please sign in to comment.