From patchwork Wed Oct 19 13:54:05 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 684118 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3szYMs4vJxz9sCZ for ; Thu, 20 Oct 2016 00:54:31 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=Nf024JBS; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type; q=dns; s=default; b=uHuMOiC7k6MbJq4HY hHYp8gI+kijMdf52tZ8bXmI0T7FE551NLPVrRP+pijOT6a/LEm2jJtc4v5Ntn/JV pNfDXLvPYso6sMWb2cWvMn7GbaB4i/mqek8qCmba1ATH5XBr81cl8rHZ7ggw27lY IkPVjqJRuC5HfAspTSJqnmWcKQ= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type; s=default; bh=KlKoBbwbi5VzXq7jpegZMun wo4Y=; b=Nf024JBSMviTIQSZHYd8Z/2VNFmLtATsoa+fC9UG2v7omr5VKJQq0Se N6nj3H0xX865IpgkDO3RrRBzUEOylh1DmmZI/gPAlaW9YF9cu1B+J2VvL7KFGRMG D+9V6QkDkDdgSCZ6fYhMJZJudvh2WtEDItVqPgxOCMvIk48M9ccs= Received: (qmail 61802 invoked by alias); 19 Oct 2016 13:54:20 -0000 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 Received: (qmail 61777 invoked by uid 89); 19 Oct 2016 13:54:19 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=1234, pedantic-errors, pedanticerrors, forbids X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 19 Oct 2016 13:54:09 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E99FC7F7A9; Wed, 19 Oct 2016 13:54:07 +0000 (UTC) Received: from reynosa.quesejoda.com (vpn-62-245.rdu2.redhat.com [10.10.62.245]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u9JDs5Cj030034; Wed, 19 Oct 2016 09:54:06 -0400 Subject: Re: PING: new pass to warn on questionable uses of alloca() and VLAs To: Eric Botcazou References: <5798785F.8020001@redhat.com> <1862342.tNhR1r4CZ5@polaris> <065d9abf-241b-0f33-2678-c51121450fa0@redhat.com> <1529599.q91eAtYeXi@polaris> Cc: gcc-patches@gcc.gnu.org, Jeff Law From: Aldy Hernandez Message-ID: <2974c6f7-f1db-e1b8-3908-0689ce5b3016@redhat.com> Date: Wed, 19 Oct 2016 09:54:05 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.3.0 MIME-Version: 1.0 In-Reply-To: <1529599.q91eAtYeXi@polaris> On 10/19/2016 09:24 AM, Eric Botcazou wrote: >> It seems to me that there is a precedence for -W type tests to start >> with a capital letter, as opposed to a lowercase letter: >> >> $ cd gcc.dg >> $ ls W[a-z]* |wc >> 280 280 5816 >> >> Do you think it would perhaps be reasonable to rename all of them to >> uppercase? > > Yes, I agree that this would be more consistent. > >> You could take -Wvla-[1-7].c and I can take the subsequent ones? > > Not sure if this wouldn't make us tread on each other's toe. ;-) I'd just > rename your 3 new testcases (-Wvla-larger-than-1.c, Wvla-larger-than-2.c and > Walloca-11.c probably) and promote the existing wvla-[1-7].c to uppercase. > Done. I have committed the attached patch as mostly obvious :). commit e066ee667cec9a90478deff7b3090587ae11236f Author: aldyh Date: Wed Oct 19 13:52:43 2016 +0000 * gcc.dg/Wvla-1.c: Rename to... * gcc.dg/Wvla-larger-than-1.c: ...this. * gcc.dg/Wvla-2.c: Rename to... * gcc.dg/Wvla-larger-than-2.c: ...this. * gcc.dg/Wvla-3.c: Rename to... * gcc.dg/Walloca-11.c.: ...this. * gcc.dg/wvla-[1-7].c: Rename to: * gcc.dg/Wvla-[1-7].c: ...this. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@241344 138bc75d-0d04-0410-961f-82ee72b054a4 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index a270700..d3d269d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,14 @@ +2016-10-19 Aldy Hernandez + + * gcc.dg/Wvla-1.c: Rename to... + * gcc.dg/Wvla-larger-than-1.c: ...this. + * gcc.dg/Wvla-2.c: Rename to... + * gcc.dg/Wvla-larger-than-2.c: ...this. + * gcc.dg/Wvla-3.c: Rename to... + * gcc.dg/Walloca-11.c.: ...this. + * gcc.dg/wvla-[1-7].c: Rename to: + * gcc.dg/Wvla-[1-7].c: ...this. + 2016-10-19 Bin Cheng PR tree-optimization/78005 diff --git a/gcc/testsuite/gcc.dg/Walloca-11.c b/gcc/testsuite/gcc.dg/Walloca-11.c new file mode 100644 index 0000000..5124476 --- /dev/null +++ b/gcc/testsuite/gcc.dg/Walloca-11.c @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-options "-Walloca -O2" } */ + +// Make sure we don't warn on VLA with -Walloca. + +void f (void*); + +void h1 (unsigned n) +{ + int a [n]; + f (a); +} diff --git a/gcc/testsuite/gcc.dg/Wvla-1.c b/gcc/testsuite/gcc.dg/Wvla-1.c index 384c930..d2e3cb5 100644 --- a/gcc/testsuite/gcc.dg/Wvla-1.c +++ b/gcc/testsuite/gcc.dg/Wvla-1.c @@ -1,24 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-Wvla-larger-than=100 -O2" } */ +/* { dg-options "-std=c89 -Wvla" } */ -typedef __SIZE_TYPE__ size_t; - -extern void useit (char *); - -int num; - -void test_vlas (size_t num) -{ - char str2[num]; /* { dg-warning "unbounded use" } */ - useit(str2); - - num = 98; - for (int i=0; i < 1234; ++i) { - char str[num]; // OK, VLA in a loop, but it is a - // known size *AND* the compiler takes - // care of cleaning up between - // iterations with - // __builtin_stack_restore. - useit(str); - } -} +extern void +func (int i, int array[i]); /* { dg-warning "ISO C90 forbids variable length array 'array'" } */ diff --git a/gcc/testsuite/gcc.dg/Wvla-2.c b/gcc/testsuite/gcc.dg/Wvla-2.c index 96814dc..92c67ed 100644 --- a/gcc/testsuite/gcc.dg/Wvla-2.c +++ b/gcc/testsuite/gcc.dg/Wvla-2.c @@ -1,70 +1,5 @@ /* { dg-do compile } */ -/* { dg-require-effective-target stdint_types } */ -/* { dg-options "-O2 -Wvla-larger-than=40" } */ +/* { dg-options "-std=c99 -Wvla" } */ -#include - -void f0 (void *); -void -f1 (__SIZE_TYPE__ a) -{ - if (a <= 10) - { - // 10 * 4 bytes = 40: OK! - uint32_t x[a]; - f0 (x); - } -} - -void -f2 (__SIZE_TYPE__ a) -{ - if (a <= 11) - { - // 11 * 4 bytes = 44: Not OK. - uint32_t x[a]; // { dg-warning "array may be too large" } - // { dg-message "note:.*argument may be as large as 44" "note" { target *-*-* } 25 } - f0 (x); - } -} - -void -f3 (__SIZE_TYPE__ a, __SIZE_TYPE__ b) -{ - if (a <= 5 && b <= 3) - { - // 5 * 3 * 4 bytes = 60: Not OK. - uint32_t x[a][b]; // { dg-warning "array may be too large" } - f0 (x); - } -} - -void -f4 (__SIZE_TYPE__ a, __SIZE_TYPE__ b) -{ - if (a <= 5 && b <= 2) - { - // 5 * 2 * 4 bytes = 40 bytes: OK! - uint32_t x[a][b]; - f0 (x); - } -} - -void -f5 (__SIZE_TYPE__ len) -{ - // Test that a direct call to __builtin_alloca_with_align is not - // confused with a VLA. - void *p = __builtin_alloca_with_align (len, 8); - f0 (p); -} - -void -f6 (unsigned stuff) -{ - int n = 7000; - do { - char a[n]; // { dg-warning "variable-length array is too large" } - f0 (a); - } while (stuff--); -} +extern void +func (int i, int array[i]); /* { dg-warning "ISO C90 forbids variable length array 'array'" } */ diff --git a/gcc/testsuite/gcc.dg/Wvla-3.c b/gcc/testsuite/gcc.dg/Wvla-3.c index 5124476..45132fa 100644 --- a/gcc/testsuite/gcc.dg/Wvla-3.c +++ b/gcc/testsuite/gcc.dg/Wvla-3.c @@ -1,12 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-Walloca -O2" } */ +/* { dg-options "-pedantic-errors -std=c89 -Wvla" } */ -// Make sure we don't warn on VLA with -Walloca. - -void f (void*); - -void h1 (unsigned n) -{ - int a [n]; - f (a); -} +extern void +func (int i, int array[i]); /* { dg-error "ISO C90 forbids variable.* array 'array'" } */ diff --git a/gcc/testsuite/gcc.dg/Wvla-4.c b/gcc/testsuite/gcc.dg/Wvla-4.c new file mode 100644 index 0000000..ae2e0b0 --- /dev/null +++ b/gcc/testsuite/gcc.dg/Wvla-4.c @@ -0,0 +1,5 @@ +/* { dg-do compile } */ +/* { dg-options "-pedantic-errors -std=c99 -Wvla" } */ + +extern void +func (int i, int array[i]); /* { dg-warning "ISO C90 forbids variable length array 'array'" } */ diff --git a/gcc/testsuite/gcc.dg/Wvla-5.c b/gcc/testsuite/gcc.dg/Wvla-5.c new file mode 100644 index 0000000..919b8dc --- /dev/null +++ b/gcc/testsuite/gcc.dg/Wvla-5.c @@ -0,0 +1,5 @@ +/* { dg-do compile } */ +/* { dg-options "-pedantic-errors -std=c89 -Wno-vla" } */ + +extern void +func (int i, int array[i]); diff --git a/gcc/testsuite/gcc.dg/Wvla-6.c b/gcc/testsuite/gcc.dg/Wvla-6.c new file mode 100644 index 0000000..694a4cc --- /dev/null +++ b/gcc/testsuite/gcc.dg/Wvla-6.c @@ -0,0 +1,5 @@ +/* { dg-do compile } */ +/* { dg-options "-std=c89 -Wvla" } */ + +extern void +func (int i, int [i]); /* { dg-warning "ISO C90 forbids variable length array" } */ diff --git a/gcc/testsuite/gcc.dg/Wvla-7.c b/gcc/testsuite/gcc.dg/Wvla-7.c new file mode 100644 index 0000000..4c264f0 --- /dev/null +++ b/gcc/testsuite/gcc.dg/Wvla-7.c @@ -0,0 +1,5 @@ +/* { dg-do compile } */ +/* { dg-options "-pedantic-errors -std=c89 -Wvla" } */ + +extern void +func (int i, int [i]); /* { dg-error "ISO C90 forbids variable" } */ diff --git a/gcc/testsuite/gcc.dg/Wvla-larger-than-1.c b/gcc/testsuite/gcc.dg/Wvla-larger-than-1.c new file mode 100644 index 0000000..384c930 --- /dev/null +++ b/gcc/testsuite/gcc.dg/Wvla-larger-than-1.c @@ -0,0 +1,24 @@ +/* { dg-do compile } */ +/* { dg-options "-Wvla-larger-than=100 -O2" } */ + +typedef __SIZE_TYPE__ size_t; + +extern void useit (char *); + +int num; + +void test_vlas (size_t num) +{ + char str2[num]; /* { dg-warning "unbounded use" } */ + useit(str2); + + num = 98; + for (int i=0; i < 1234; ++i) { + char str[num]; // OK, VLA in a loop, but it is a + // known size *AND* the compiler takes + // care of cleaning up between + // iterations with + // __builtin_stack_restore. + useit(str); + } +} diff --git a/gcc/testsuite/gcc.dg/Wvla-larger-than-2.c b/gcc/testsuite/gcc.dg/Wvla-larger-than-2.c new file mode 100644 index 0000000..96814dc --- /dev/null +++ b/gcc/testsuite/gcc.dg/Wvla-larger-than-2.c @@ -0,0 +1,70 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target stdint_types } */ +/* { dg-options "-O2 -Wvla-larger-than=40" } */ + +#include + +void f0 (void *); +void +f1 (__SIZE_TYPE__ a) +{ + if (a <= 10) + { + // 10 * 4 bytes = 40: OK! + uint32_t x[a]; + f0 (x); + } +} + +void +f2 (__SIZE_TYPE__ a) +{ + if (a <= 11) + { + // 11 * 4 bytes = 44: Not OK. + uint32_t x[a]; // { dg-warning "array may be too large" } + // { dg-message "note:.*argument may be as large as 44" "note" { target *-*-* } 25 } + f0 (x); + } +} + +void +f3 (__SIZE_TYPE__ a, __SIZE_TYPE__ b) +{ + if (a <= 5 && b <= 3) + { + // 5 * 3 * 4 bytes = 60: Not OK. + uint32_t x[a][b]; // { dg-warning "array may be too large" } + f0 (x); + } +} + +void +f4 (__SIZE_TYPE__ a, __SIZE_TYPE__ b) +{ + if (a <= 5 && b <= 2) + { + // 5 * 2 * 4 bytes = 40 bytes: OK! + uint32_t x[a][b]; + f0 (x); + } +} + +void +f5 (__SIZE_TYPE__ len) +{ + // Test that a direct call to __builtin_alloca_with_align is not + // confused with a VLA. + void *p = __builtin_alloca_with_align (len, 8); + f0 (p); +} + +void +f6 (unsigned stuff) +{ + int n = 7000; + do { + char a[n]; // { dg-warning "variable-length array is too large" } + f0 (a); + } while (stuff--); +} diff --git a/gcc/testsuite/gcc.dg/wvla-1.c b/gcc/testsuite/gcc.dg/wvla-1.c deleted file mode 100644 index d2e3cb5..0000000 --- a/gcc/testsuite/gcc.dg/wvla-1.c +++ /dev/null @@ -1,5 +0,0 @@ -/* { dg-do compile } */ -/* { dg-options "-std=c89 -Wvla" } */ - -extern void -func (int i, int array[i]); /* { dg-warning "ISO C90 forbids variable length array 'array'" } */ diff --git a/gcc/testsuite/gcc.dg/wvla-2.c b/gcc/testsuite/gcc.dg/wvla-2.c deleted file mode 100644 index 92c67ed..0000000 --- a/gcc/testsuite/gcc.dg/wvla-2.c +++ /dev/null @@ -1,5 +0,0 @@ -/* { dg-do compile } */ -/* { dg-options "-std=c99 -Wvla" } */ - -extern void -func (int i, int array[i]); /* { dg-warning "ISO C90 forbids variable length array 'array'" } */ diff --git a/gcc/testsuite/gcc.dg/wvla-3.c b/gcc/testsuite/gcc.dg/wvla-3.c deleted file mode 100644 index 45132fa..0000000 --- a/gcc/testsuite/gcc.dg/wvla-3.c +++ /dev/null @@ -1,5 +0,0 @@ -/* { dg-do compile } */ -/* { dg-options "-pedantic-errors -std=c89 -Wvla" } */ - -extern void -func (int i, int array[i]); /* { dg-error "ISO C90 forbids variable.* array 'array'" } */ diff --git a/gcc/testsuite/gcc.dg/wvla-4.c b/gcc/testsuite/gcc.dg/wvla-4.c deleted file mode 100644 index ae2e0b0..0000000 --- a/gcc/testsuite/gcc.dg/wvla-4.c +++ /dev/null @@ -1,5 +0,0 @@ -/* { dg-do compile } */ -/* { dg-options "-pedantic-errors -std=c99 -Wvla" } */ - -extern void -func (int i, int array[i]); /* { dg-warning "ISO C90 forbids variable length array 'array'" } */ diff --git a/gcc/testsuite/gcc.dg/wvla-5.c b/gcc/testsuite/gcc.dg/wvla-5.c deleted file mode 100644 index 919b8dc..0000000 --- a/gcc/testsuite/gcc.dg/wvla-5.c +++ /dev/null @@ -1,5 +0,0 @@ -/* { dg-do compile } */ -/* { dg-options "-pedantic-errors -std=c89 -Wno-vla" } */ - -extern void -func (int i, int array[i]); diff --git a/gcc/testsuite/gcc.dg/wvla-6.c b/gcc/testsuite/gcc.dg/wvla-6.c deleted file mode 100644 index 694a4cc..0000000 --- a/gcc/testsuite/gcc.dg/wvla-6.c +++ /dev/null @@ -1,5 +0,0 @@ -/* { dg-do compile } */ -/* { dg-options "-std=c89 -Wvla" } */ - -extern void -func (int i, int [i]); /* { dg-warning "ISO C90 forbids variable length array" } */ diff --git a/gcc/testsuite/gcc.dg/wvla-7.c b/gcc/testsuite/gcc.dg/wvla-7.c deleted file mode 100644 index 4c264f0..0000000 --- a/gcc/testsuite/gcc.dg/wvla-7.c +++ /dev/null @@ -1,5 +0,0 @@ -/* { dg-do compile } */ -/* { dg-options "-pedantic-errors -std=c89 -Wvla" } */ - -extern void -func (int i, int [i]); /* { dg-error "ISO C90 forbids variable" } */