From patchwork Thu Aug 25 13:21:15 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 111566 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 49BF5B6F81 for ; Thu, 25 Aug 2011 23:21:38 +1000 (EST) Received: (qmail 18059 invoked by alias); 25 Aug 2011 13:21:35 -0000 Received: (qmail 18050 invoked by uid 22791); 25 Aug 2011 13:21:33 -0000 X-SWARE-Spam-Status: No, hits=-3.5 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from cantor2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 25 Aug 2011 13:21:17 +0000 Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.221.2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx2.suse.de (Postfix) with ESMTP id E294C8FC92 for ; Thu, 25 Aug 2011 15:21:15 +0200 (CEST) Date: Thu, 25 Aug 2011 15:21:15 +0200 (CEST) From: Richard Guenther To: gcc-patches@gcc.gnu.org Subject: [PATCH] Restore gcc.dg/Wshadow-3.c Message-ID: User-Agent: Alpine 2.00 (LNX 1167 2008-08-23) MIME-Version: 1.0 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org This patch restores gcc.dg/Wshadow-3.c which was overwritten by r148442. I noticed this by the strange test name for a test checking -Warray-bounds warnings ... Committed. (reversed patch below) Richard. 2011-08-25 Richard Guenther * gcc.dg/Wshadow-3.c: Restore original content destroyed by r148442. Index: testsuite/gcc.dg/Wshadow-3.c =================================================================== --- testsuite/gcc.dg/Wshadow-3.c (revision 148441) +++ testsuite/gcc.dg/Wshadow-3.c (revision 148442) @@ -1,21 +1,61 @@ -/* Test warnings for shadowing in function prototype scope: generally - useless but of use if the parameter is used within the scope. Bug - 529. */ -/* Origin: Joseph Myers */ +/* PR middle-end/36902 Array bound warning with dead code after optimization */ /* { dg-do compile } */ -/* { dg-options "-std=gnu89 -Wshadow" } */ +/* { dg-options "-O2 -Warray-bounds -Wall -Wextra" } */ +typedef unsigned char __u8; +typedef unsigned short __u16; -int v; /* { dg-warning "shadowed declaration" } */ -int f1(int v); -int f2(int v, int x[v]); /* { dg-warning "declaration of 'v' shadows a global declaration" } */ -int f3(int v, int y[sizeof(v)]); /* { dg-warning "declaration of 'v' shadows a global declaration" } */ -int f4(int v) { return 0; } /* { dg-warning "declaration of 'v' shadows a global declaration" } */ -int f5(int v, int x[v]) { return 0; } /* { dg-warning "declaration of 'v' shadows a global declaration" } */ -int f6(int x) { return 0; } -int f7(v) int v; { return 0; } /* { dg-warning "declaration of 'v' shadows a global declaration" } */ -int f8(v, w) int v; int w[v]; { return 0; } /* { dg-warning "declaration of 'v' shadows a global declaration" } */ -int f9(x) int x; { return 0; } -int f10(v) { return 0; } /* { dg-warning "declaration of 'v' shadows a global declaration" } */ -int f11(int a, int b(int a)); -int f12(int a, int b(int a, int x[a])); /* { dg-warning "declaration of 'a' shadows a parameter" } */ -/* { dg-warning "shadowed declaration" "outer parm" { target *-*-* } 20 } */ +static inline unsigned char * +foo(unsigned char * to, const unsigned char * from, int n) +{ + switch ( n ) + { + case 3: + *to = *from; + break; + case 5: + to[4] = from [4]; + break; + } + return to; +} + +struct { + int size_of_select; + unsigned char pcr_select[4]; +} sel; + +int bar(void) +{ + static unsigned char buf[64]; + + sel.size_of_select = 3; + foo(buf, sel.pcr_select, sel.size_of_select); + + return 1; +} + + +static inline unsigned char * +foo2(unsigned char * to, const unsigned char * from, int n) +{ + switch ( n ) + { + case 3: + *to = *from; + break; + case 5: + to[63] = from [111]; /* { dg-warning "array subscript is above array bounds" } */ + break; + } + return to; +} + +int baz(void) +{ + static unsigned char buf[64]; + + sel.size_of_select = 5; + foo2(buf, sel.pcr_select, sel.size_of_select); + + return 1; +}