https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108721

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
In the reduced testcase there is certainly an aliasing violation.
struct {
  unsigned f0
} g_95 = {65531};
...
*g_412 = &g_95;
...
  --g_95.f0;
  *g_86 = g_613 || 0;
  *g_412 = 0;
  short *l_873 = &g_95;
  --*l_873;
even after making g_412 unsigned *g_412 = &g_95.f0; it gets different results,
but
while short *l_873 = &g_95.f0; does as well, doing
  typedef short sa __attribute__((may_alias));
  sa *l_873 = &g_95.f0;
one gets the same result.
Now, in the original testcase it actually uses
union U0 {
   uint16_t f0;
   int64_t f1;
   int64_t f2;
   uint32_t f3;
};
static union U0 g_95 = {65531UL};
but then has
static int64_t *g_279 = &g_95.f2;
...
    int64_t *l_939 = &g_95.f2;
...
        uint16_t *l_873 = &g_95.f0;
...
                uint32_t *l_933[8] =
{&g_95.f3,&g_95.f3,&g_95.f3,&g_95.f3,&g_95.f3,&g_95.f3,&g_95.f3,&g_95.f3};
...
        int64_t *l_425 = &g_95.f2;
...
        uint16_t *l_597 = &g_95.f0;
etc.  Now, all of this doesn't necessarily mean it is UB, but it is a strong
indication that it very likely is.  Standard C/C++ doesn't allow type punning
through union, only one of the members can be active at a time, GCC allows it,
but for aliasing requires that accesses have the union type visible to the
compiler on the access.  Taking addresses of different union members means that
most likely that isn't followed, UB would be whenever some union member is
stored and another one read through a pointer without the union in access path
etc.

Now, I think some of the readings of the standard say that whenever say
uint16_t and uint32_t appear in some union anywhere, one basically needs to
treat them as the same alias set, but such reading makes TBAA totally useless. 
So if csmith follows that reading, it is indeed unsafe for TBAA.

Reply via email to