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

--- Comment #5 from Bernd Edlinger <bernd.edlinger at hotmail dot de> ---
Using named struct members does not make a difference.
Of course it is possible that converting address of u.b.z
to const char *, makes the example undefined, as strlen is
not really accessing the bytes thru a union member.

$ cat pr87053.c
/* PR middle-end/87053 */

const union
{ struct {
    char x[4];
    char y[4];
  } a;
  struct {
    char z[8];
  } b;
} u = {{"1234", "567"}};

int main ()
{
  if (__builtin_strlen (u.b.z) != 7)
    __builtin_abort ();
}
$ gcc pr87053.c
gcc -O3 -S pr87053.c 
pr87053.c: In function ‘main’:
pr87053.c:15:28: warning: ‘strlen’ argument missing terminating nul
[-Wstringop-overflow=]
15 |   if (__builtin_strlen (u.b.z) != 7)
   |                         ~~~^~
pr87053.c:11:3: note: referenced argument declared here
11 | } u = {{"1234", "567"}};
   |   ^
pr87053.c:15:28: warning: ‘strlen’ argument missing terminating nul
[-Wstringop-overflow=]
15 |   if (__builtin_strlen (u.b.z) != 7)
   |                         ~~~^~
pr87053.c:11:3: note: referenced argument declared here
11 | } u = {{"1234", "567"}};
   |   ^

Reply via email to