Richard Guenther <[EMAIL PROTECTED]> wrote on 15/12/2005 14:52:27:

> On 12/15/05, Dorit Naishlos <[EMAIL PROTECTED]> wrote:
>
> > So, in short - when can we assume that pointer types have the minimum
> > alignment required by their underlying type?
>
> I think the C standard always guarantees this.

As far as I saw in the C standard, if you convert a pointer to a type to a
pointer to a different type and the resulting pointer is not correctly
aligned for the pointed-to type, then the behavior is undefined. Can we
conclude from that the behavior of un-naturally-aligned pointers in general
is undefined (even when it's not a result of unsafe casts)?

> Of course with packed
> structs or malicious users this is not always true but may (at least in
> the case of malicious users) be invoking unspecified behavior.
>

Does the testcase in PR25413 fall into the category of "malicious users"?
This is the relevant code snippet from the testcase:

===========================================
struct oct_tt;
typedef struct oct_tt oct_t;
typedef unsigned int var_t;
typedef enum {
  OCT_EMPTY = 0,
  OCT_NORMAL = 1,
  OCT_CLOSED = 2
} oct_state;
struct oct_tt {
  var_t n;
  int ref;
  oct_state state;
  struct oct_tt* closed;
  num_t* c;
};

oct_t*
octfapg_universe (const var_t n)
{
  oct_t* m;
  size_t i, nn = (2*(size_t)(n)*((size_t)(n)+1));
  m = octfapg_alloc(n);
  for (i=0;i<nn;i++) *(m->c+i) = num__infty;    ## <-- the loop
  .....
  return m;
}
============================

When we vectorize the loop above, we assume that the dataref *(m->c+i),
which is of type double, is aligned on size of double, whereas it turns out
that on some targets it isn't. What did the user do wrong here? (there are
no bad type casts, or even usage of attribute "packed").

And what is GCC's policy w.r.t packed-structs? are we not guaranteeing to
compile references to fields of packed-structs correctly when they violate
natural-alignment? (as in this testcase:
http://gcc.gnu.org/viewcvs/branches/apple-local-200502-branch/gcc/testsuite/gcc.dg/vect/vect-align-1.c?rev=108214&view=markup)


My concern is that these testcases are handled correctly by GCC if
vectorization is not enabled. Is it just "accidental" that the unvectorized
code provides the expected behavior, or is the vectorizer making an
assumption it shouldn't be making?

thanks,
dorit


> Richard.

Reply via email to