[Bug middle-end/108721] [10/11/12/13 Regression] csmith: really old bug with -O2

2023-02-16 Thread jakub at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108721

Jakub Jelinek  changed:

   What|Removed |Added

 Resolution|--- |INVALID
 Status|UNCONFIRMED |RESOLVED

--- Comment #5 from Jakub Jelinek  ---
Ok, trying the original testcase compiled with -O0 -g and awatch g_95.f1 in
gdb,
g_95.f0 is read/modified directly, then
(*p_9) = (((**g_412) = ((safe_mod_func_uint8_t_u_u(p_10,
(safe_div_func_uint32_t_u_u(((safe_lshift_func_uint8_t_u_u(((safe_lshift_func_int16_t_s_s&g_95
!= &g_95) || ((*g_86) = (g_613[1] || (*g_245 | (l_799 < 0UL)), 1)) ^ (p_10
== (0x95L != 247UL))), p_10)) , l_799), 5L >= 0x7BC3L)) < l_799);
stores 0 to it through int64_t * (g_412[0] is &g_95.f1) and is read from it
immediately again.
Then
(*l_871) = (safe_mul_func_int8_t_s_s(((1UL > ((void*)0 == l_871)) <
(--(*l_873))), ((l_876 , ((*l_878) = l_877)) >
(safe_sub_func_int8_t_s_s(((safe_sub_func_uint64_t_u_u(((safe_div_func_int16_t_s_ssafe_sub_func_uint8_t_u_ul_887
!= l_888) != ((safe_add_func_uint64_t_u_u((*l_3), (((--g_118.f0) > ((*l_872) =
(*l_871))) , g_594))) || l_894)) == g_20.f0), (*l_3))) | (*l_3)) >
4294967288UL), g_207[3][7][2])) > 0xCA172E9FL), (*l_3))) < 1L), 0UL);
reads it through uint16_t * pointer l_873.  I think that is enough UBs to mark
this as invalid.

[Bug middle-end/108721] [10/11/12/13 Regression] csmith: really old bug with -O2

2023-02-16 Thread jakub at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108721

--- Comment #4 from Jakub Jelinek  ---
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.

[Bug middle-end/108721] [10/11/12/13 Regression] csmith: really old bug with -O2

2023-02-15 Thread dcb314 at hotmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108721

--- Comment #3 from David Binderman  ---
Created attachment 54471
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54471&action=edit
C source code

After a short reduction.