This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug middle-end/78154] memcpy et al can be assumed to return non-null


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

--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
As a data point, although it also doesn't optimize away the abort in the test
case in comment #0, Clang does eliminate it when it determines that the first
argument is non-null as in the modified test case below.  GCC loses that
information.

$ cat b.c && /build/llvm-trunk/bin/clang -O2 -S -Wall -Wextra -Wpedantic
-o/dev/stdout --target=sparcv9-solaris2.12 b.c

extern void* memcpy (void*, const void*, __SIZE_TYPE__);

void f (void *d, const void *s, __SIZE_TYPE__ n)
{
  if (d && __builtin_memcpy (d, s, n) == 0)
    __builtin_abort ();
}

        .text
        .file   "b.c"
        .globl  f
        .align  4
        .type   f,@function
f:                                      ! @f
! BB#0:                                 ! %entry
        save %sp, -176, %sp
        cmp %i0, 0
        be %xcc, .LBB0_2
        nop
! BB#1:                                 ! %land.lhs.true
        mov      %i0, %o0
        mov      %i1, %o1
        call memcpy
        mov      %i2, %o2
.LBB0_2:                                ! %if.end
        ret
        restore
.Lfunc_end0:
        .size   f, .Lfunc_end0-f


        .ident  "clang version 3.8.0 (trunk 251144)"
        .section        ".note.GNU-stack"

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]