From patchwork Fri Dec 2 12:19:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 701947 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 3tVYBQ2Hk1z9t1P for ; Fri, 2 Dec 2016 23:19:56 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="wpwRenfa"; 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:to:cc :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=AAUseFgLLofLLjIc6Q8IUdLngBGqNSTL11IFItFI6EWUgRByt8 tLRVhvYpSoZMWsJ5t+SNuFe3Fjb7fa33duj4+fF1LTEPQ3d5ir+CDPhaUkXKGaO+ /7G17+wUovfvK+SXzyQSUQhWOC33o9udUKbLKD2EE7HEsFWZ0T7dHYX44= 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:to:cc :from:subject:message-id:date:mime-version:content-type; s= default; bh=8pAB+shv8FgXZUqPqigbVicq/aE=; b=wpwRenfaoNTJR75vc2eT 3NK+7jRQs+Ni11aKU5rzsjFUWh/1vxfPTCVOnH8HqHj0ZHTHi2rtS3Ic5s71JO5z 1A0GQfQHQDglKW2MJ3nUto+R6MRvPFTBiddGPTG8cOgQRbQJ8eXqLvCwMPDuNx+S FW4A5G9eA0jxJkEMQnEtqgQ= Received: (qmail 64227 invoked by alias); 2 Dec 2016 12:19:47 -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 64216 invoked by uid 89); 2 Dec 2016 12:19:46 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.8 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=drill 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; Fri, 02 Dec 2016 12:19:44 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 F40309D770 for ; Fri, 2 Dec 2016 12:19:42 +0000 (UTC) Received: from reynosa.quesejoda.com (vpn-57-24.rdu2.redhat.com [10.10.57.24]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id uB2CJf58026862; Fri, 2 Dec 2016 07:19:41 -0500 To: gcc-patches Cc: Jeff Law From: Aldy Hernandez Subject: [PR middle-end/78328] [committed] wrong wording for unbounded alloca case Message-ID: <6883ab26-9f9a-571c-feaf-16b30c872e62@redhat.com> Date: Fri, 2 Dec 2016 07:19:40 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 The problem here is that as we follow the cast from an unsigned int to __SIZE_TYPE__, we ignore the VR_ANTI_RANGE of 7 exhibited by the test in the PR: +void g (unsigned int n) +{ + if (n == 7) + n = 11; + f (__builtin_alloca (n)); +} Since we can't get any meaningful information from VR_ANTI_RANGE as we drill down to a cast, the appropriate thing is to drop it without assuming it has a range. This was as oversight in not handling VR_ANTI_RANGE gracefully, and I'll go on a limb here and say that attached patch is obvious. Committed to trunk. commit 59256dfdee704d08bcd20f0576abd3353f5767cc Author: Aldy Hernandez Date: Fri Dec 2 04:42:26 2016 -0500 PR middle-end/78328 * gimple-ssa-warn-alloca.c (alloca_call_type): Handle VR_ANTI_RANGE. diff --git a/gcc/gimple-ssa-warn-alloca.c b/gcc/gimple-ssa-warn-alloca.c index e75f2fa..ae379f9 100644 --- a/gcc/gimple-ssa-warn-alloca.c +++ b/gcc/gimple-ssa-warn-alloca.c @@ -339,6 +339,8 @@ alloca_call_type (gimple *stmt, bool is_vla, tree *invalid_casted_type) { // Fall through. } + else if (range_type == VR_ANTI_RANGE) + return alloca_type_and_limit (ALLOCA_UNBOUNDED); else if (range_type != VR_VARYING) return alloca_type_and_limit (ALLOCA_BOUND_MAYBE_LARGE, max); diff --git a/gcc/testsuite/gcc.dg/Walloca-12.c b/gcc/testsuite/gcc.dg/Walloca-12.c new file mode 100644 index 0000000..5d71cda --- /dev/null +++ b/gcc/testsuite/gcc.dg/Walloca-12.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "-Walloca-larger-than=128 -O2" } */ + +void f (void*); + +void g (unsigned int n) +{ + if (n == 7) + n = 11; + f (__builtin_alloca (n)); /* { dg-warning "unbounded use of 'alloca'" } */ +}