From patchwork Mon Mar 20 18:51:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 741142 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 3vn4nC3vWwz9s3w for ; Tue, 21 Mar 2017 05:52:13 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="u/SSO0Cr"; 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:date :from:to:cc:subject:message-id:mime-version:content-type; q=dns; s=default; b=VMF6GCgyL/IDf8oM2my2yKPEjE7gaG5Nywfd2cPhXo8MrqQTWW 7chl8hv7qp6a5mUSe0U5LW4dpFvtWhryee/BzdJl8zL8Vm6K5iXZBXf5IyThMIds 8ftCZXgkeZtI5HT0ck9pTdCnIRhuXYNnhl8y0Rs7nJCRW8PsgYODsDcE0= 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:date :from:to:cc:subject:message-id:mime-version:content-type; s= default; bh=2z+Gh/d4DdOmAmdnnp+7zKGI2X8=; b=u/SSO0Crt3QzMN+1X6Yb dOFKC9LZFbb3i8IpjHhikENCIXLHK+aZV9gbOfU4n1Z98RCAWjhcPW5Eu6+vGRTD XLAxtGqqg2flRlPBDztXlFiFeEuRovYnhbE5EtZ8HX4VDswsqntT4bXeeNZqstNv 63vk2mD2M1Nm1TIZ2/A8Fyw= Received: (qmail 2795 invoked by alias); 20 Mar 2017 18:51:56 -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 2773 invoked by uid 89); 20 Mar 2017 18:51:55 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= 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; Mon, 20 Mar 2017 18:51:53 +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 83D5E7E9DE for ; Mon, 20 Mar 2017 18:51:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 83D5E7E9DE Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=polacek@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 83D5E7E9DE Received: from redhat.com (ovpn-204-27.brq.redhat.com [10.40.204.27]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2KIpob2001604 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 20 Mar 2017 14:51:53 -0400 Date: Mon, 20 Mar 2017 19:51:49 +0100 From: Marek Polacek To: GCC Patches Cc: Aldy Hernandez , Martin Sebor , Jeff Law Subject: [PATCH] Fix ICE on invalid with -Walloca-larger-than (PR tree-optimization/80109) Message-ID: <20170320185149.GK3172@redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.7.1 (2016-10-04) We crash with this invalid testcase because we aren't properly checking what we are passing down to get_range_info, i.e., we can't pass a pointer. So fixed by checking the argument first, and calling alloca_type_and_limit if it is of a wrong type. Bootstrapped/regtested on x86_64-linux, ok for trunk? 2017-03-20 Marek Polacek Martin Sebor PR tree-optimization/80109 * gimple-ssa-warn-alloca.c (alloca_call_type): Only call get_range_info on INTEGRAL_TYPE_P. * gcc.dg/Walloca-14.c: New test. Marek diff --git gcc/gimple-ssa-warn-alloca.c gcc/gimple-ssa-warn-alloca.c index b940efa..ec95cc6 100644 --- gcc/gimple-ssa-warn-alloca.c +++ gcc/gimple-ssa-warn-alloca.c @@ -327,11 +327,20 @@ alloca_call_type (gimple *stmt, bool is_vla, tree *invalid_casted_type) // away with better range information. But it gets // most of the cases. gimple *def = SSA_NAME_DEF_STMT (len); - if (gimple_assign_cast_p (def) - && TYPE_UNSIGNED (TREE_TYPE (gimple_assign_rhs1 (def)))) + if (gimple_assign_cast_p (def)) { - len_casted = gimple_assign_rhs1 (def); - range_type = get_range_info (len_casted, &min, &max); + tree rhs1 = gimple_assign_rhs1 (def); + tree rhs1type = TREE_TYPE (rhs1); + + // Bail if the argument type is not valid. + if (!INTEGRAL_TYPE_P (rhs1type)) + return alloca_type_and_limit (ALLOCA_OK); + + if (TYPE_UNSIGNED (rhs1type)) + { + len_casted = rhs1; + range_type = get_range_info (len_casted, &min, &max); + } } // An unknown range or a range of the entire domain is // really no range at all. diff --git gcc/testsuite/gcc.dg/Walloca-14.c gcc/testsuite/gcc.dg/Walloca-14.c index e69de29..6ff2e7f 100644 --- gcc/testsuite/gcc.dg/Walloca-14.c +++ gcc/testsuite/gcc.dg/Walloca-14.c @@ -0,0 +1,12 @@ +/* PR tree-optimization/80109 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -Walloca-larger-than=126812070" } */ + +void +g (int *p) +{ + extern void f (void *); + + void *q = __builtin_alloca (p); /* { dg-warning "passing argument 1" } */ + f (q); +}