From patchwork Tue Feb 12 01:13:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Sebor X-Patchwork-Id: 1040308 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-495914-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="L7fh9CcI"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="AoQ1KC5n"; dkim-atps=neutral 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 43z4Rv304Kz9s3x for ; Tue, 12 Feb 2019 12:14:03 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=J2VIcAtpZz0PrqGPvbUQzQGJbDspFZ9czKBcVH5UDJWdyTO7h2 vixkyALg3DyfJyCXatOPh5BoVw5Pum7xFU/9Cvz82vyTMwYxWlAD6vonW4B9WJUY yQkVhxPxocMXpHPAJjC570RDHqvtR+NLS9jmxivAXNWKAZztXa2g2NWGc= 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 :from:subject:message-id:date:mime-version:content-type; s= default; bh=qfdfwplfsKJYhmxzhUXDpm2d+hQ=; b=L7fh9CcIGtqczM/1SfzT zd6eCH7haMInVEhp5dmXs3kINT50kRceS91BPxefSVCjZ4D3n9slAuz9W02RWtVM R76IQamfhHk0xboWAdex8mtYG8NbcF1A2l2DCmvz61zb0/dcLMRsU83CHoudT88t LEVls/HoSHNB9b3UMIzzkeY= Received: (qmail 9337 invoked by alias); 12 Feb 2019 01:13: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 9328 invoked by uid 89); 12 Feb 2019 01:13:56 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=grateful X-HELO: mail-qt1-f196.google.com Received: from mail-qt1-f196.google.com (HELO mail-qt1-f196.google.com) (209.85.160.196) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 12 Feb 2019 01:13:54 +0000 Received: by mail-qt1-f196.google.com with SMTP id v10so1084291qtp.8 for ; Mon, 11 Feb 2019 17:13:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:from:subject:message-id:date:user-agent:mime-version :content-language; bh=3FTeQdubUviXqkxW9Phc8jRSNrJSLdIV+Fe4h+cd8Z8=; b=AoQ1KC5nUuMuL/L7BRZ/BBEKbHpYxlvpHK2/fmi+Fq5bTV8hWuP/znkj0Jvt8AHTd0 cvC9C3npCt5U96pAnuhQDwzWM8AIWPhNYbrR+HyAHXKd3bReGqStYtXs4gPbZ0YM4H5W zYQjAVTKOgD9aMjZcGP4+wsQpiXH0/oxo7D+ChJSuGlLA3T15UxOdvqoBBcEtnCpNDPC QPQbZIubkF0LsXoIGtrx4grTjBi5yCm4jC5DL89cxZwU/7/U5AV82OYJvBDV039O2l0S 8ONf5LJedksOFTcszoQhoZ/HGFKt1r3sdxvtIMEXE9gYAC71g5BnOfGMMwt+PDI9vB7R onyw== Received: from [192.168.0.106] (174-16-97-54.hlrn.qwest.net. [174.16.97.54]) by smtp.gmail.com with ESMTPSA id z207sm12542013qka.57.2019.02.11.17.13.50 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 11 Feb 2019 17:13:51 -0800 (PST) To: "gcc-patches@gcc.gnu.org" From: Martin Sebor Subject: [PATCH] Avoid assuming valid_constant_size_p argument is a constant expression (PR 89294) Message-ID: <90ec17e4-779f-4847-873e-78567681cf6a@gmail.com> Date: Mon, 11 Feb 2019 18:13:50 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.1 MIME-Version: 1.0 X-IsSubscribed: yes The attached patch removes the assumption introduced earlier today in my fix for bug 87996 that the valid_constant_size_p argument is a constant expression. I couldn't come up with a C/C++ test case where this isn't true but apparently it can happen in Ada which I inadvertently didn't build. I still haven't figured out what I have to do to build it on my Fedora 29 machine so I tested this change by hand (besides bootstrapping w/o Ada). The first set of instructions Google gives me don't seem to do it: https://fedoraproject.org/wiki/Features/Ada_developer_tools and neither does dnf install gcc-gnat as explained on our Wiki: https://gcc.gnu.org/wiki/GNAT If someone knows the magic chant I would be grateful (it might be helpful to also update the Wiki page -- the last change to it was made in 2012; I volunteer to do that). Martin PR middle-end/89294 - ICE in valid_constant_size_p gcc/c-family/ChangeLog: PR middle-end/89294 * c-common.c (invalid_array_size_error): Handle cst_size_not_constant. gcc/ChangeLog: PR middle-end/89294 * tree.c (valid_constant_size_p): Avoid assuming size is a constant expression. * tree.h (cst_size_error): Add the cst_size_not_constant enumerator. Index: gcc/c-family/c-common.c =================================================================== --- gcc/c-family/c-common.c (revision 268783) +++ gcc/c-family/c-common.c (working copy) @@ -8241,6 +8241,13 @@ invalid_array_size_error (location_t loc, cst_size tree maxsize = max_object_size (); switch (error) { + case cst_size_not_constant: + if (name) + error_at (loc, "size of array %qE is not a constant expression", + name); + else + error_at (loc, "size of array is not a constant expression"); + break; case cst_size_negative: if (name) error_at (loc, "size %qE of array %qE is negative", Index: gcc/tree.c =================================================================== --- gcc/tree.c (revision 268783) +++ gcc/tree.c (working copy) @@ -7521,8 +7521,14 @@ valid_constant_size_p (const_tree size, cst_size_e if (!perr) perr = &error; - if (TREE_OVERFLOW (size)) + if (TREE_CODE (size) != INTEGER_CST) { + *perr = cst_size_not_constant; + return false; + } + + if (TREE_OVERFLOW_P (size)) + { *perr = cst_size_overflow; return false; } Index: gcc/tree.h =================================================================== --- gcc/tree.h (revision 268783) +++ gcc/tree.h (working copy) @@ -4352,6 +4352,7 @@ extern tree excess_precision_type (tree); is not a valid size. */ enum cst_size_error { cst_size_ok, + cst_size_not_constant, cst_size_negative, cst_size_too_big, cst_size_overflow