Bug 30028 - [4.3 Regression] bcopy is wrongly converted to memcpy
Summary: [4.3 Regression] bcopy is wrongly converted to memcpy
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: 4.3.0
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2006-11-30 12:19 UTC by Kazumoto Kojima
Modified: 2006-12-01 03:51 UTC (History)
3 users (show)

See Also:
Host:
Target: sh-elf, spu-elf
Build:
Known to work:
Known to fail:
Last reconfirmed: 2006-11-30 18:14:15


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kazumoto Kojima 2006-11-30 12:19:29 UTC
gcc.c-torture/execute/builtins/memops-asm.c fails on sh-elf
with -O1 and higher.  It seems that bcopy is converted to memcpy
even when source and destination area are overlapped.  It looks
same tests start to fail also on ia64 and s390 testresults.  They
don't fail on i686, but a similar testcase

typedef __SIZE_TYPE__ size_t;
extern void abort (void);
extern void bcopy (const void *, void *, size_t);
extern int memcmp (const void *, const void *, size_t);

char y[64] = "foXXXrfoobar";

int
main ()
{
  bcopy (y + 1, y + 2, 6);
  if (memcmp (y, "fooXXXrfobar", 13))
    abort ();
  return 0;
}

aborts with -O1 on i686-pc-linux-gnu for revision 119302.
If the resent changes of builtins.c in r119292 and r119294 are
reverted, the errors go away.
Comment 1 Richard Biener 2006-11-30 13:52:17 UTC
This is honza again.
Comment 2 Jan Hubicka 2006-11-30 14:11:33 UTC
Subject: Re:  [4.3 Regression] bcopy is wrongly converted to memcpy

Hi,
there is nice typo on the check validating the transformation.  I am
testing the patch and will commit it as obvious if it passes.

Honza

Index: builtins.c
===================================================================
--- builtins.c	(revision 119360)
+++ builtins.c	(working copy)
@@ -8176,7 +8176,7 @@ fold_builtin_memory_op (tree arglist, tr
 	  if (dest_align && src_align
 	      && (readonly_data_expr (src)
 	          || (host_integerp (len, 1)
-		      && (MIN (src_align, dest_align) / BITS_PER_UNIT <=
+		      && (MIN (src_align, dest_align) / BITS_PER_UNIT >=
 			  tree_low_cst (len, 1)))))
 	    {
 	      tree fn = implicit_built_in_decls[BUILT_IN_MEMCPY];
Comment 3 Andrew Pinski 2006-11-30 18:14:15 UTC
This also fails for spu-elf.
Confirmed.
http://gcc.gnu.org/ml/gcc-testresults/2006-11/msg01291.html
Comment 4 Jan Hubicka 2006-11-30 19:36:21 UTC
Subject: Bug 30028

Author: hubicka
Date: Thu Nov 30 19:36:02 2006
New Revision: 119375

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=119375
Log:
	PR middle-end/30028
	* builtins.c (fold_builtin_memory_op): Fix typo in the check for
	memmove/bcopy->memcpy conversion.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/builtins.c

Comment 5 Andrew Pinski 2006-12-01 03:51:10 UTC
Confirmed fixed.
Comment 6 patchapp@dberlin.org 2006-12-07 18:25:19 UTC
Subject: Bug number PR30028

A patch for this bug has been added to the patch tracker.
The mailing list url for the patch is http://gcc.gnu.org/ml/gcc-patches/2006-12/msg00499.html