From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28262 invoked by alias); 30 Jan 2019 22:15:29 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 28137 invoked by uid 89); 30 Jan 2019 22:15:21 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-0.9 required=5.0 tests=BAYES_00,KAM_LAZY_DOMAIN_SECURITY,RCVD_IN_DNSWL_NONE autolearn=no version=3.3.2 spammy= X-HELO: mail-qt1-f172.google.com Received: from mail-qt1-f172.google.com (HELO mail-qt1-f172.google.com) (209.85.160.172) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 30 Jan 2019 22:15:20 +0000 Received: by mail-qt1-f172.google.com with SMTP id v11so1429231qtc.2 for ; Wed, 30 Jan 2019 14:15:15 -0800 (PST) Return-Path: Received: from [192.168.1.115] (209-6-216-142.s141.c3-0.smr-cbr1.sbo-smr.ma.cable.rcncustomer.com. [209.6.216.142]) by smtp.gmail.com with ESMTPSA id r56sm3030570qtj.30.2019.01.30.14.15.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 30 Jan 2019 14:15:12 -0800 (PST) Subject: Re: [PATCH] print correct array sizes in errors (PR 87996) To: Martin Sebor , "gcc-patches@gcc.gnu.org" References: <0b3c92dc-6d35-d4cb-b2df-536432523bab@gmail.com> From: Jason Merrill Message-ID: <0d772e1d-648d-ce03-38fc-7d8dd6ad1201@redhat.com> Date: Wed, 30 Jan 2019 22:17:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.1 MIME-Version: 1.0 In-Reply-To: <0b3c92dc-6d35-d4cb-b2df-536432523bab@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2019-01/txt/msg01750.txt.bz2 On 1/29/19 7:15 PM, Martin Sebor wrote: > + /* Try to convert the original SIZE to a ssizetype. */ > + if (orig_size != error_mark_node > + && !TYPE_UNSIGNED (TREE_TYPE (orig_size))) > + { > + if (TREE_CODE (size) == INTEGER_CST > + && tree_int_cst_sign_bit (size)) > + diagsize = build_converted_constant_expr (ssizetype, size, > + tsubst_flags_t ()); > + else if (size == error_mark_node > + && TREE_CODE (orig_size) == INTEGER_CST > + && tree_int_cst_sign_bit (orig_size)) > + diagsize = build_converted_constant_expr (ssizetype, orig_size, > + tsubst_flags_t ()); > + } Using build_converted_constant_expr here looks odd; that's a language-level notion, and we're dealing with compiler internals. fold_convert seems more appropriate. > + if (TREE_CONSTANT (size)) > + { > + if (!diagsize && TREE_CODE (size) == INTEGER_CST) > + diagsize = size; > + } > + else > size = osize; > } > > @@ -9732,15 +9758,12 @@ compute_array_index_type_loc (location_t name_loc, > if (TREE_CODE (size) == INTEGER_CST) > { > /* An array must have a positive number of elements. */ > - if (!valid_constant_size_p (size)) > + if (!diagsize) > + diagsize = size; It seems like the earlier hunk here is unnecessary; if size is an INTEGER_CST, it will be unchanged, and so be used for diagsize in the latter hunk without any changes to the earlier location. Actually, why not do all of the diagsize logic down here? There doesn't seem to be anything above that relies on information we will have lost at this point. Jason