This is the mail archive of the gcc-patches@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]

[PATCH] builtins: Report error for negative length argument for memset


Hi,

calling memset with a zero or negative length argument and
enabling optimization on S/390 currently leads to an ICE in
s390_expand_setmem.

With the attached patch GCC does not try to expand the builtin
when a negative length argument was given and calls the 
lib function instead. Addtionally an error is reported.

Ok for mainline given it bootstraps without testsuite regressions?

Bye,

-Andreas-


2007-04-23  Andreas Krebbel  <krebbel1@de.ibm.com>

	PR target/31641
	* builtins.c (expand_builtin_memset_args): Report error for a constant
	length argument below 0.
	* config/s390/s390.c (s390_expand_setmem): Don't ICE for constant length
	argument of 0 for memset.


Index: gcc/builtins.c
===================================================================
*** gcc/builtins.c.orig	2007-04-03 16:07:04.000000000 +0200
--- gcc/builtins.c	2007-04-23 12:32:37.000000000 +0200
*************** expand_builtin_memset_args (tree dest, t
*** 3873,3878 ****
--- 3873,3884 ----
    len_rtx = expand_normal (len);
    dest_mem = get_memory_rtx (dest, len);
  
+   if (host_integerp (len, 1) && tree_low_cst (len, 1) < 0)
+     {
+       error ("%<__builtin_memset%> called with negative length argument");
+       goto do_libcall;
+     }
+ 
    if (TREE_CODE (val) != INTEGER_CST)
      {
        rtx val_rtx;
Index: gcc/config/s390/s390.c
===================================================================
*** gcc/config/s390/s390.c.orig	2007-04-23 10:39:27.000000000 +0200
--- gcc/config/s390/s390.c	2007-04-23 12:56:40.000000000 +0200
*************** s390_expand_movmem (rtx dst, rtx src, rt
*** 3605,3610 ****
--- 3605,3613 ----
  void
  s390_expand_setmem (rtx dst, rtx len, rtx val)
  {
+   if (GET_CODE (len) == CONST_INT && INTVAL (len) == 0)
+     return;
+ 
    gcc_assert (GET_CODE (len) != CONST_INT || INTVAL (len) > 0);
    gcc_assert (GET_CODE (val) == CONST_INT || GET_MODE (val) == QImode);
    


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