From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10121 invoked by alias); 6 Nov 2002 02:42:05 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 10109 invoked from network); 6 Nov 2002 02:42:03 -0000 Received: from unknown (HELO dr-evil.shagadelic.org) (208.176.2.168) by sources.redhat.com with SMTP; 6 Nov 2002 02:42:03 -0000 Received: by dr-evil.shagadelic.org (Postfix, from userid 7518) id 9E8759842; Tue, 5 Nov 2002 18:42:03 -0800 (PST) Date: Tue, 05 Nov 2002 18:42:00 -0000 From: Jason R Thorpe To: Richard Henderson , John David Anglin , gcc-patches@gcc.gnu.org, jakub@redhat.com Subject: Re: [PATCH] Fix some -Wunreachable-code issues Message-ID: <20021105184203.I27156@dhcp7.wlan.shagadelic.org> Mail-Followup-To: Jason R Thorpe , Richard Henderson , John David Anglin , gcc-patches@gcc.gnu.org, jakub@redhat.com References: <20021102164740.N29066@dhcp7.wlan.shagadelic.org> <200211030110.gA31AJpQ016617@hiauly1.hia.nrc.ca> <20021105151516.H27156@dhcp7.wlan.shagadelic.org> <20021105232002.GB20967@redhat.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="BwCQnh7xodEAoBMC" Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <20021105232002.GB20967@redhat.com>; from rth@redhat.com on Tue, Nov 05, 2002 at 03:20:02PM -0800 Organization: Wasabi Systems, Inc. X-SW-Source: 2002-11/txt/msg00254.txt.bz2 --BwCQnh7xodEAoBMC Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 330 On Tue, Nov 05, 2002 at 03:20:02PM -0800, Richard Henderson wrote: > Fails for INT_MAX < 0x7fffffff. Should check limits.h > and chose either int or long. D'oh. Fixed thus. * gcc.dg/duff-1.c: New test. * gcc.dg/duff-2.c: New test. * gcc.dg/duff-3.c: New test. -- -- Jason R. Thorpe --BwCQnh7xodEAoBMC Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=duff-test-patch Content-length: 4021 Index: gcc.dg/duff-1.c =================================================================== RCS file: gcc.dg/duff-1.c diff -N gcc.dg/duff-1.c *** /dev/null 1 Jan 1970 00:00:00 -0000 --- gcc.dg/duff-1.c 6 Nov 2002 02:35:33 -0000 *************** *** 0 **** --- 1,50 ---- + /* Duff's device is legal C; test to make sure the compiler + doesn't complain about it. + + Jason Thorpe + Derived from PR 3846. */ + + /* { dg-do run } */ + /* { dg-options "-O2" } */ + + extern void abort (void); + extern void exit (int); + + typedef __SIZE_TYPE__ size_t; + extern int memcmp (const void *, const void *, size_t); + + void + duffcpy (char *dst, const char *src, unsigned long size) + { + switch (size & 3) + { + for (;;) + { + *dst++ = *src++; + case 3: + *dst++ = *src++; + case 2: + *dst++ = *src++; + case 1: + *dst++ = *src++; + case 0: + if (size <= 3) + break; + size -= 4; + } + } + } + + const char testpat[] = "The quick brown fox jumped over the lazy dog."; + + int + main() + { + char buf[64]; + + duffcpy (buf, testpat, sizeof (testpat)); + if (memcmp (buf, testpat, sizeof (testpat)) != 0) + abort (); + + exit (0); + } Index: gcc.dg/duff-2.c =================================================================== RCS file: gcc.dg/duff-2.c diff -N gcc.dg/duff-2.c *** /dev/null 1 Jan 1970 00:00:00 -0000 --- gcc.dg/duff-2.c 6 Nov 2002 02:35:33 -0000 *************** *** 0 **** --- 1,60 ---- + /* Duff's device is legal C; test to make sure the compiler + doesn't complain about it. + + Jason Thorpe + Derived from the BSD Telnet Kerberos 4 checksum routine. + See also PR 5230. */ + + /* { dg-do run } */ + /* { dg-options "-O2" } */ + + extern void abort (void); + extern void exit (int); + + #if __INT_MAX__ >= 2147483647 + /* At least 32-bit integers. */ + typedef int type32; + #else + typedef long type32; + #endif + + type32 + cksum (const unsigned char *src, unsigned long size) + { + type32 ck = 0; + + switch (size & 3) + { + while (size > 0) + { + case 0: + ck ^= (type32)*src++ << 24; + --size; + case 3: + ck ^= (type32)*src++ << 16; + --size; + case 2: + ck ^= (type32)*src++ << 8; + --size; + case 1: + ck ^= (type32)*src++; + --size; + } + } + + return ck; + } + + const char testpat[] = "The quick brown fox jumped over the lazy dog."; + + int + main() + { + type32 ck; + + ck = cksum ((const unsigned char *) testpat, sizeof (testpat)); + if (ck != 925902908) + abort (); + + exit (0); + } Index: gcc.dg/duff-3.c =================================================================== RCS file: gcc.dg/duff-3.c diff -N gcc.dg/duff-3.c *** /dev/null 1 Jan 1970 00:00:00 -0000 --- gcc.dg/duff-3.c 6 Nov 2002 02:35:33 -0000 *************** *** 0 **** --- 1,47 ---- + /* Duff's device is legal C; test to make sure the compiler + doesn't complain about it. + + Jason Thorpe + Derived from Tom Duff's original usenet message about the device. */ + + /* { dg-do run } */ + /* { dg-options "-O2" } */ + + extern void abort (void); + extern void exit (int); + + typedef __SIZE_TYPE__ size_t; + extern int memcmp (const void *, const void *, size_t); + + void + duffcpy (char *dst, const char *src, unsigned long size) + { + unsigned long n = (size + 7) / 8; + + switch (size % 8) + { + case 0: do { *dst++ = *src++; + case 7: *dst++ = *src++; + case 6: *dst++ = *src++; + case 5: *dst++ = *src++; + case 4: *dst++ = *src++; + case 3: *dst++ = *src++; + case 2: *dst++ = *src++; + case 1: *dst++ = *src++; + } while (--n > 0); + } + } + + const char testpat[] = "The quick brown fox jumped over the lazy dog."; + + int + main() + { + char buf[64]; + + duffcpy (buf, testpat, sizeof (testpat)); + if (memcmp (buf, testpat, sizeof (testpat)) != 0) + abort (); + + exit (0); + } --BwCQnh7xodEAoBMC--