summaryrefslogtreecommitdiffstats
path: root/contrib/gcc
diff options
context:
space:
mode:
authorobrien <obrien@FreeBSD.org>2002-06-04 18:04:27 +0000
committerobrien <obrien@FreeBSD.org>2002-06-04 18:04:27 +0000
commitd047bea9fd8a46067c6343b55baba16ef0b809c5 (patch)
treea9cccfa427db33d82ac3a56d0b13f6eb1c452660 /contrib/gcc
parent845c7be0e802934c939612825c8534aad41c0bf9 (diff)
downloadFreeBSD-src-d047bea9fd8a46067c6343b55baba16ef0b809c5.zip
FreeBSD-src-d047bea9fd8a46067c6343b55baba16ef0b809c5.tar.gz
Gcc 3.1 (-O) now generates broken inline code for memset in some cases.
This broke newfs (newfs left some garbage in a bitmap). The ASM for: #include <string.h> int x, foo[100]; main() { memset(&foo[0], 0, x); } is (at least if you have fixed function alignment): .file "z.c" .text .p2align 2,,3 .globl main .type main,@function main: pushl %ebp movl %esp, %ebp pushl %edi pushl %eax movl x, %ecx xorl %eax, %eax shrl $2, %ecx movl $foo, %edi cld rep stosl andl $-16, %esp <-- the lower bits of `len' should be loaded near here testl $2, %edi <-- this seems to be meant to test the 2^1 bit in `len' (not alignment of the pointer like it actually does). %edi is the wrong register for holding the bits, since it is still needed for the pointer. je .L2 stosw .L2: testl $1, %edi <-- similarly for the 2^0 bit. je .L3 stosb .L3: movl -4(%ebp), %edi leave ret .Lfe1: .size main,.Lfe1-main .comm foo,400,32 .comm x,4,4 .ident "GCC: (GNU) 3.1 [FreeBSD] 20020509 (prerelease)" This seems to only result in (len % 3) bytes not being cleared, since gcc doesn't seem to use the builtin memset unless it knows that the pointer is aligned. If %edi could be misaligned, then too many bytes would be set. Submitted by: BDE
Diffstat (limited to 'contrib/gcc')
-rw-r--r--contrib/gcc/builtins.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/contrib/gcc/builtins.c b/contrib/gcc/builtins.c
index 7eb878f7..22e66b6 100644
--- a/contrib/gcc/builtins.c
+++ b/contrib/gcc/builtins.c
@@ -19,6 +19,8 @@ along with GCC; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA. */
+/* $FreeBSD$ */
+
#include "config.h"
#include "system.h"
#include "machmode.h"
@@ -2194,6 +2196,11 @@ expand_builtin_memset (exp, target, mode)
len_rtx = expand_expr (len, NULL_RTX, VOIDmode, 0);
+ /* Give up for non-constant lengths. They are broken on at least
+ i386's. */
+ if (GET_CODE (len_rtx) != CONST_INT)
+ return 0;
+
dest_mem = get_memory_rtx (dest);
set_mem_align (dest_mem, dest_align);
dest_addr = clear_storage (dest_mem, len_rtx);
OpenPOWER on IntegriCloud