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

--- Comment #3 from prathamesh3492 at gcc dot gnu.org ---
Created attachment 40183
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=40183&action=edit
revert part of r242745 for strcat, strcat_chk, strncat, strncat_chk

Hi,
Unfortunately I haven't been able to reproduce the issue on aarch64-none-elf
with (almost) identical configure opts with make-check,
and neither did it get caught by our validation matrix.
I would be grateful for suggestions on how to build strcat-chk.c standalone.
It seems it depends on lib/chk.c and possibly other files ?
I tried a few approaches but none of them worked :/

Regarding the code-gen difference "cmp x0, x0", I have verified that is not
caused by my patch.
The same can be reproduced with the following test-case before r242745.

char *f(char *dest, char *src)
{
  if (__builtin_strcpy (dest + 5, src) != (dest + 5))
    __builtin_abort ();
}

-O2 shows following assembly for aarch64-none-elf:
f:
        add     x2, x0, 5
        stp     x29, x30, [sp, -16]!
        mov     x0, x2
        add     x29, sp, 0
        bl      strcpy
        cmp     x0, x0
        bne     .L5
        ldp     x29, x30, [sp], 16
        ret

This seems to start after "pro_and_epilogue" pass, which probably realizes
strcpy returns 1st arg.
The dump of the pass contains the following insn:
(insn 13 36 14 2 (set (reg:CC 66 cc)
        (compare:CC (reg/f:DI 0 x0 [orig:73 _1 ] [73])
            (reg:DI 0 x0))) "foo2.c":3 393 {cmpdi}
     (nil))

Full dump: http://pastebin.com/sUmg09SK

Apparently, this is also observed on x86_64-unknown-linux-gnu:
f:
.LFB0:
        .cfi_startproc
        leaq    5(%rdi), %rdx
        subq    $8, %rsp
        .cfi_def_cfa_offset 16
        movq    %rdx, %rdi
        call    strcpy
        cmpq    %rax, %rax
        jne     .L5
        addq    $8, %rsp
        .cfi_remember_state
        .cfi_def_cfa_offset 8
        ret

The reason it started showing up this for strcat/strcat_chk is because r242745
changed attribute of BUILT_IN_STRCAT_CHK
and BUILT_IN_STRCAT from ATTR_NOTHROW_NONNULL_LEAF to
ATTR_RET1_NOTHROW_NONNULL_LEAF, which is same as for strcpy.
Could you check if reverting that change (attached patch), doesn't cause the
issue ?

Thanks,
Prathamesh

Reply via email to