http://gcc.gnu.org/bugzilla/show_bug.cgi?id=61054

            Bug ID: 61054
           Summary: Clearly note effect of memcpy optimization
                    improvements in 4.9 changes
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: web
          Assignee: unassigned at gcc dot gnu.org
          Reporter: harald at gigawatt dot nl

Consider this reduced program:

void *volatile null;
volatile long zerolen;

int main() {
  void *dst = null, *src = null;
  __builtin_memcpy (dst, src, zerolen);
  if (dst) __builtin_abort ();
}

This program is invalid, but until 4.8 it would compile and run without an
issue. As of 4.9, it aborts.

I'm not asking for GCC to change (the programs should be fixed instead), but it
is not clear from the GCC 4.9 Changes page that such code no longer works. This
affects real code using custom allocators and realloc-like functions, where
some of those realloc-like functions don't bother to check for null pointers
and assume zero-length memcpy is a no-op. When the old memory is then freed,
and their free-like function performs a null pointer check, that check is
optimised away if the function gets inlined.

Could the GCC 4.9 Changes page get a mention of this?

I do see "Better inlining of memcpy and memset that is aware of value ranges
and produces shorter alignment prologues." in the IA-32/x86-64 section, but I
cannot tell if it is related to that, or if it is actually arch-independent.

Reply via email to