public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "mikpe at it dot uu.se" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug other/56881] Miscompilation (optimisation failure?) causing NULL dereference and segfault at runtime
Date: Sun, 14 Apr 2013 08:56:00 -0000	[thread overview]
Message-ID: <bug-56881-4-P3wnJCaVMh@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-56881-4@http.gcc.gnu.org/bugzilla/>


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

Mikael Pettersson <mikpe at it dot uu.se> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|mikpe at it dot uu.se       |

--- Comment #8 from Mikael Pettersson <mikpe at it dot uu.se> 2013-04-14 08:56:47 UTC ---
The error is in the test case.  It overrides the libc memmove() with its own
implementation, but that implementation fails to follow the specification.  In
particular, it returns NULL rather than memmove()'s first parameter.

GCC now optimizes based on this aspect of the specification, so things go wrong
at runtime.

Correcting the test case as follows allows it to work with gcc 4.8 and 4.9:

--- unix.c.~1~  2013-03-06 23:17:26.000000000 +0100
+++ unix.c      2013-04-14 10:45:24.651407693 +0200
@@ -110,7 +110,7 @@ memmove(void *dp, const void *sp, size_t
        unsigned char *cdp, *csp;

        if (n<=0)
-               return 0;
+               return dp;
        cdp = dp;
        csp = (unsigned char *)sp;
        if (cdp < csp) {
@@ -124,6 +124,6 @@ memmove(void *dp, const void *sp, size_t
                        *--cdp = *--csp;
                } while (--n);
        }
-       return 0;
+       return dp;
 }
 #endif

Not a bug in GCC.  Please close as INVALID.


  parent reply	other threads:[~2013-04-14  8:56 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-08 16:48 [Bug other/56881] New: " devspam at moreofthesa dot me.uk
2013-04-09 13:57 ` [Bug other/56881] " devspam at moreofthesa dot me.uk
2013-04-09 14:45 ` mikpe at it dot uu.se
2013-04-10 14:49 ` devspam at moreofthesa dot me.uk
2013-04-10 15:02 ` devspam at moreofthesa dot me.uk
2013-04-13 17:53 ` mikpe at it dot uu.se
2013-04-13 20:39 ` mikpe at it dot uu.se
2013-04-14  8:56 ` mikpe at it dot uu.se [this message]
2013-04-14 15:24 ` steven at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-56881-4-P3wnJCaVMh@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).