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

            Bug ID: 87053
           Summary: wrong code with c_strlen
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bernd.edlinger at hotmail dot de
  Target Milestone: ---

$ cat u.c
const union
{ struct {
    char x[4];
    char y[4];
  };
  struct {
    char z[8];
  };
} u = {{"1234", "567"}};

int test()
{
  return __builtin_strlen(u.z);
}
$ gcc -S u.c
$ 
cat u.s
        .file   "u.c"
        .text
        .globl  u
        .section        .rodata
        .align 8
        .type   u, @object
        .size   u, 8
u:
        .ascii  "1234"
        .string "567"
        .text
        .globl  test
        .type   test, @function
test:
.LFB0:
        .cfi_startproc
        pushq   %rbp
        .cfi_def_cfa_offset 16
        .cfi_offset 6, -16
        movq    %rsp, %rbp
        .cfi_def_cfa_register 6
        movl    $4, %eax
        popq    %rbp
        .cfi_def_cfa 7, 8
        ret
        .cfi_endproc
.LFE0:
        .size   test, .-test
        .ident  "GCC: (GNU) 9.0.0 20180821 (experimental)"
        .section        .note.GNU-stack,"",@progbits

which Looks wrong.
expected: not folded, or evaluate to 7.

Reply via email to