Someone at IBM working on a very large project on s390 showed me some odd code
in which two memcpy calls get merged into something that instead spreads one
character into the final destination.  A modification of that code that looks
more normal is:

char string2[9] = "1234";
void
foo (void)
{
  char temp[4];
  char *p = &string2[2];
  memcpy (&temp, &string2[1], 4);
  memcpy (p, &temp, 4);
  string2[1] = '.';
}

The result in string2 should be "1.234" but is "1.2222" (or so says the person
who reported this to me).  I'll attach the full test case with both versions of
the code.

Based on my examination of the generated s390 code, which I had never seen
before and just barely understand, this was broken in 3.0 through 3.4, OK in
4.0 through 4.2, and is broken again in 4.3.


-- 
           Summary: two memcpy calls merged incorrectly with -O1
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: janis at gcc dot gnu dot org
GCC target triplet: s390-unknown-linux-gnu


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

Reply via email to