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

            Bug ID: 102238
           Summary: alias_offset in gimple-ssa-sprintf.c is broken
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
  Target Milestone: ---

Take:
/* 
   { dg-do compile }
   { dg-options "-O2 -Wno-format-overflow -Wrestrict -ftrack-macro-expansion=0"
}
*/
void sink (int);
#define S10 "0123456789"
extern char a2[2][22];
#define T(d, ...) do {                                  \
    char a[22] = S10;                                   \
    sink (__builtin_sprintf ((d), __VA_ARGS__));        \
  } while (0)
struct S {
  char a[4];
  char b[4];
};
struct S2 {
  struct S s_1;
  struct S s_2;
  struct S sa3[3];
};
struct S3 {
  struct S2 s2_1;
  struct S2 s2_2;

  struct {
    struct {
      struct {
        struct S sa_3[3];
      } a_1[3];
    } a_2[3][3];
  } a_3[3][3][3];

  char fa[];
};
void test_struct_member_array (struct S3 *s3, int i)
{
  char *a = (char*)s3;
  char *d;
  const char *s;
  d = s3->s2_2.s_1.a;
  s = s3->s2_2.s_1.a;
  T (d, "%s", a + 40);   /* { dg-warning "overlaps" } */
  T (d, "%s", a + 41);   /* { dg-warning "may overlap" } */
  T (d, "%s", a + 42);   /* { dg-warning "may overlap" } */
}

----- CUT -----

This should warn but does not.
The reason is alias_offset does not do a good job at all figuring out field
offsets.

Reply via email to