jkmcnk / sx-gcc

The GNU Compiler Collection port to NEC SX CPU architecture.
GNU General Public License v2.0
0 stars 2 forks source link

The "gcc.c-torture/execute/align-1.c" test case fails if compiled with sx-gcc. #74

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
This test case is very simple:

{{{

typedef int new_int __attribute__ ((aligned(16)));
struct S { int x; };

int main()
{
  if (sizeof(struct S) != sizeof(int))
    abort ();
  return 0;
}

}}}

The test case generates the following assembly code:

    lds $s35,.LC1   #movdi case3
    lea $s36,0
    sts $s36,-280(,$s2)
    lea $s34,-280(,$s2)
    or  $s33,0,$s35
    bsic    $s32,($s33)

We can see that there is no jumps, which would be expected when compiling
the "if" statement. As a consequence, the "abort" function is always executed.

Original issue reported on code.google.com by nou...@gmail.com on 11 Dec 2008 at 3:57

GoogleCodeExporter commented 8 years ago
Looks like the sx-gcc proclaims already at compile time that the "sizeof(struct 
S) !=
sizeof(int)" condition is be always true.

Original comment by nou...@gmail.com on 11 Dec 2008 at 4:00

GoogleCodeExporter commented 8 years ago
If I insert the "printf" functions to print out the values of the "sizeof" 
function,

{{{

typedef int new_int __attribute__ ((aligned(16)));
struct S { int x; };

int main()
{
  printf("sizeof(struct S) = %lld\n", sizeof(struct S));
  printf("sizeof(int) = %lld\n", sizeof(int));
  if (sizeof(struct S) != sizeof(int))
    abort ();
  return 0;
}

}}}

I get the following output:

sizeof(struct S) = 8
sizeof(int) = 4
ABORT instruction (core dumped)

So it is obvious the sizes don't match.

Original comment by nou...@gmail.com on 11 Dec 2008 at 4:31

GoogleCodeExporter commented 8 years ago
Could this be an alignment issue (if I remember correctly the default alignment 
with
SX is 8-bytes)?

Furthermore, if I replace the "int" type with the "new_int":

{{{

typedef int new_int __attribute__ ((aligned(16)));
struct S { new_int x; };

int main()
{
  printf("sizeof(struct S) = %lld\n", sizeof(struct S));
  printf("sizeof(new_int) = %lld\n", sizeof(new_int));
  if (sizeof(struct S) != sizeof(new_int))
    abort ();
  return 0;
}

}}}

I get the following printout:

sizeof(struct S) = 16
sizeof(int) = 4
ABORT instruction (core dumped)

Original comment by nou...@gmail.com on 11 Dec 2008 at 4:43

GoogleCodeExporter commented 8 years ago
this was caused by us requiring structure size alignment of 64 bits (sx.h, macro
STRUCTURE_SIZE_BOUNDARY).

I am certain that there is nothing about our target that would require this, 
thus I
removed the macro in r165 (resetting the boundary to its default of 8 bits), 
which
fixes this issue.

Original comment by jmoc...@gmail.com on 11 Dec 2008 at 6:57