This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] builtins: Report error for negative length argument for memset
- From: Andreas Krebbel <Andreas dot Krebbel at de dot ibm dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: Ulrich dot Weigand at de dot ibm dot com
- Date: Mon, 23 Apr 2007 13:09:10 +0200
- Subject: [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);