RFC: is this test case OK?

Gary Funck gary@intrepid.com
Mon Jul 12 06:45:00 GMT 2010


Recently, I ran into a bug in the merge of the trunck with the
gupc branch: a statement in c-typeck.c in the trunk had inadvertently
been deleted, and this caused a regression on IA64.

The attached test case detects the regression (that user-requested
16 byte alignment is handled correctly).  I'll follow-up with an RFA
if this test case is considered well-formed, useful, and not duplicative.

Three questions:
1) Is the use of __alignof__ acceptable?
2) Is the cast of an address to (unsigned long int)
suitably portable?  If not, is there another recommended
method for making this check?
3) Would it be reasonable to place this test in
testsuite/gcc.dg?

I'm concerned that the final 'if' which tests that the address
is 16 byte aligned might not be portable enough across all
targets.  For example, does a 16 bit word target processor
have to honor the 16 byte alignment, or is it a "best efforts"
sort of thing?

thanks,
- Gary
-------------- next part --------------
/* 
   Test that the alignment of a typedef'd array
   is honored when applied to a struct field.

   { dg-do run }
   { dg-options "" }
*/

extern void abort (void);

typedef struct
{
  unsigned long int __val[(1024 / (8 * sizeof (unsigned long int)))];
} __sigset_t;

typedef long __jmp_buf_16[70] __attribute__ ((aligned (16)));

struct __jmp_buf_tag_16
{
  __jmp_buf_16 __jmpbuf;
  int __mask_was_saved;
  __sigset_t __saved_mask;
};

typedef struct __jmp_buf_tag_16 jmp_buf_16[1];

char c;
jmp_buf_16 eof_buf_16;

int
main ()
{
  if (__alignof__ (__jmp_buf_16) != 16)
    abort ();
  if (__alignof__ (eof_buf_16) != 16)
    abort ();
  if (__alignof__ (eof_buf_16[0].__jmpbuf) != 16)
    abort ();
  if ((unsigned long int) eof_buf_16 & 0xFul)
    abort ();
  return 0;
}


More information about the Gcc-patches mailing list