public inbox for gcc-prs@sourceware.org help / color / mirror / Atom feed
From: fvdl@wasabisystems.com To: gcc-gnats@gcc.gnu.org Subject: optimization/7291: off-by-one in generated inline bzero code for i386 (64bit) Date: Fri, 12 Jul 2002 13:16:00 -0000 [thread overview] Message-ID: <200207122030.g6CKUae08833@k2.vaasje.org> (raw) >Number: 7291 >Category: optimization >Synopsis: off-by-one in generated inline bzero code for i386 (64bit) >Confidential: no >Severity: serious >Priority: medium >Responsible: unassigned >State: open >Class: wrong-code >Submitter-Id: net >Arrival-Date: Fri Jul 12 13:16:00 PDT 2002 >Closed-Date: >Last-Modified: >Originator: Frank van der Linden >Release: 3.1.1 20020711 (prerelease) >Organization: Wasabi Systems, Inc. >Environment: System: NetBSD k2 1.6A NetBSD 1.6A (K2) #0: Mon Jul 8 00:59:23 CEST 2002 fvdl@k2:/work/trees/empee/sys/arch/i386/compile/K2 i386 host: i386-unknown-netbsdelf1.6A build: i386-unknown-netbsdelf1.6A target: x86_64--netbsd configured with: ../../toolchain/gcc-3-1-branch/configure --target=x86_64--netbsd --with-gnu-ld --with-gas --enable-languages=c c++ --disable-shared --prefix=/work/fvdl/toolchain >Description: When inlining a call to bzero, gcc 3.1(.1) and gcc-current can some- times (depending how much it knows about alignment) generate incorrect code for a 64bit i386 (x86-64) target. The code that zeroes out the leftover bytes (i.e. bytes left to zero out after a multiple of 8 has been done) tests for the wrong bit in the number of bytes left. >How-To-Repeat: Consider the following program: ==================================================== #include <stdio.h> #include <string.h> #include <stdlib.h> int foo(int n) { unsigned ia[64]; int i; if (n > 64) return; for (i = 0; i < 64; i++) ia[i] = 0xdeadbeef; bzero(ia, n * sizeof (unsigned)); for (i = 0; i < n; i++) { if (ia[i] != 0) { printf("index %d is %x, should be 0\n", i, ia[i]); return -1; } } return 0; } int main(int argc, char **argv) { if (argc != 2) exit(1); if (foo(atoi(argv[1])) < 0) printf("check failed\n"); else printf("check ok\n"); return 0; } ================================================== When compiled with -O, it shows the off-by-one (in units of 4 bytes) error: $ uname -srm NetBSD 1.6D x86_64 $ ./a.out 31 index 30 is deadbeef, should be 0 check failed $ ./a.out 32 check ok $ ./a.out 33 index 32 is deadbeef, should be 0 check failed $ ./a.out 34 check ok $ >Fix: The following change to gcc/config/i386/i386.c fixes it: *** i386.c.orig Thu Jul 11 21:45:55 2002 --- i386.c Fri Jul 12 22:12:23 2002 *************** *** 9493,9499 **** gen_rtx_SUBREG (SImode, zeroreg, 0))); if (TARGET_64BIT && (align <= 4 || count == 0)) { ! rtx label = ix86_expand_aligntest (countreg, 2); emit_insn (gen_strsetsi (destreg, gen_rtx_SUBREG (SImode, zeroreg, 0))); emit_label (label); --- 9493,9499 ---- gen_rtx_SUBREG (SImode, zeroreg, 0))); if (TARGET_64BIT && (align <= 4 || count == 0)) { ! rtx label = ix86_expand_aligntest (countreg, 4); emit_insn (gen_strsetsi (destreg, gen_rtx_SUBREG (SImode, zeroreg, 0))); emit_label (label); >Release-Note: >Audit-Trail: >Unformatted:
next reply other threads:[~2002-07-12 20:16 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2002-07-12 13:16 fvdl [this message] 2002-09-07 12:01 sayle
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=200207122030.g6CKUae08833@k2.vaasje.org \ --to=fvdl@wasabisystems.com \ --cc=gcc-gnats@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).