From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTPS id B44F23858018 for ; Wed, 3 Nov 2021 13:15:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B44F23858018 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-431-QpDZqGwXO9eZvEvaBHf1zQ-1; Wed, 03 Nov 2021 09:15:02 -0400 X-MC-Unique: QpDZqGwXO9eZvEvaBHf1zQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 02A7A19057A4; Wed, 3 Nov 2021 13:15:01 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.193.172]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 90E051002D71; Wed, 3 Nov 2021 13:15:00 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.16.1/8.16.1) with ESMTPS id 1A3DEv7J2288210 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 3 Nov 2021 14:14:58 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.16.1/8.16.1/Submit) id 1A3DEvww2288209; Wed, 3 Nov 2021 14:14:57 +0100 Date: Wed, 3 Nov 2021 14:14:56 +0100 From: Jakub Jelinek To: Richard Biener Cc: Jason Merrill , gcc-patches@gcc.gnu.org Subject: Re: [PATCH] dwarf2out: Fix up CONST_WIDE_INT handling once more [PR103046] Message-ID: <20211103131456.GN304296@tucnak> Reply-To: Jakub Jelinek References: <20211103083536.GM304296@tucnak> <20211103092619.GC3230972@tucnak> MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-5.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 03 Nov 2021 13:15:07 -0000 On Wed, Nov 03, 2021 at 01:59:27PM +0100, Richard Biener wrote: > > case CONST_WIDE_INT: > > - { > > - wide_int w1 = rtx_mode_t (rtl, MAX_MODE_INT); > > - unsigned int prec = MIN (wi::min_precision (w1, UNSIGNED), > > - (unsigned int) CONST_WIDE_INT_NUNITS (rtl) > > - * HOST_BITS_PER_WIDE_INT); > > - wide_int w = wide_int::from (w1, prec, UNSIGNED); > > - add_AT_wide (die, DW_AT_const_value, w); > > - } > > + if (is_int_mode (mode, &int_mode) > > + && (GET_MODE_PRECISION (int_mode) > > + & (HOST_BITS_PER_WIDE_INT - 1)) == 0) > > + { > > + wide_int w = rtx_mode_t (rtl, int_mode); > > + add_AT_wide (die, DW_AT_const_value, w); > > + } > > ... this at least deserves a comment why we return true doing > nothing when the mode precision isn't a multiple of 64. The other > patch simply extended things. Oops, that is obviously a bug. For non-integral mode or mode with precision not a multiple of 64 I meant to punt. The reason for the latter is that if precision is something weird like 123 bits, then the printing code will print the whole 64-bit elt which would be wrong for at least unsigned numbers with MSB set. I guess such modes are still very rare to non-existing. 2021-11-03 Jakub Jelinek PR debug/103046 * dwarf2out.c (add_const_value_attribute): Add MODE argument, use it in CONST_WIDE_INT handling. Adjust recursive calls. (add_location_or_const_value_attribute): Pass DECL_MODE (decl) to new add_const_value_attribute argument. (tree_add_const_value_attribute): Pass TYPE_MODE (type) to new add_const_value_attribute argument. --- gcc/dwarf2out.c.jj 2021-10-08 10:52:47.086531820 +0200 +++ gcc/dwarf2out.c 2021-11-03 14:06:22.750387774 +0100 @@ -3854,7 +3854,7 @@ static void add_AT_location_description dw_loc_list_ref); static void add_data_member_location_attribute (dw_die_ref, tree, struct vlr_context *); -static bool add_const_value_attribute (dw_die_ref, rtx); +static bool add_const_value_attribute (dw_die_ref, machine_mode, rtx); static void insert_int (HOST_WIDE_INT, unsigned, unsigned char *); static void insert_wide_int (const wide_int &, unsigned char *, int); static unsigned insert_float (const_rtx, unsigned char *); @@ -20081,8 +20081,10 @@ insert_float (const_rtx rtl, unsigned ch constants do not necessarily get memory "homes". */ static bool -add_const_value_attribute (dw_die_ref die, rtx rtl) +add_const_value_attribute (dw_die_ref die, machine_mode mode, rtx rtl) { + scalar_mode int_mode; + switch (GET_CODE (rtl)) { case CONST_INT: @@ -20097,15 +20099,15 @@ add_const_value_attribute (dw_die_ref di return true; case CONST_WIDE_INT: - { - wide_int w1 = rtx_mode_t (rtl, MAX_MODE_INT); - unsigned int prec = MIN (wi::min_precision (w1, UNSIGNED), - (unsigned int) CONST_WIDE_INT_NUNITS (rtl) - * HOST_BITS_PER_WIDE_INT); - wide_int w = wide_int::from (w1, prec, UNSIGNED); - add_AT_wide (die, DW_AT_const_value, w); - } - return true; + if (is_int_mode (mode, &int_mode) + && (GET_MODE_PRECISION (int_mode) + & (HOST_BITS_PER_WIDE_INT - 1)) == 0) + { + wide_int w = rtx_mode_t (rtl, int_mode); + add_AT_wide (die, DW_AT_const_value, w); + return true; + } + return false; case CONST_DOUBLE: /* Note that a CONST_DOUBLE rtx could represent either an integer or a @@ -20190,7 +20192,7 @@ add_const_value_attribute (dw_die_ref di case CONST: if (CONSTANT_P (XEXP (rtl, 0))) - return add_const_value_attribute (die, XEXP (rtl, 0)); + return add_const_value_attribute (die, mode, XEXP (rtl, 0)); /* FALLTHROUGH */ case SYMBOL_REF: if (!const_ok_for_output (rtl)) @@ -20703,7 +20705,7 @@ add_location_or_const_value_attribute (d rtl = rtl_for_decl_location (decl); if (rtl && (CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING) - && add_const_value_attribute (die, rtl)) + && add_const_value_attribute (die, DECL_MODE (decl), rtl)) return true; /* See if we have single element location list that is equivalent to @@ -20724,7 +20726,7 @@ add_location_or_const_value_attribute (d if (GET_CODE (rtl) == EXPR_LIST) rtl = XEXP (rtl, 0); if ((CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING) - && add_const_value_attribute (die, rtl)) + && add_const_value_attribute (die, DECL_MODE (decl), rtl)) return true; } /* If this decl is from BLOCK_NONLOCALIZED_VARS, we might need its @@ -20799,7 +20801,7 @@ tree_add_const_value_attribute (dw_die_r symbols. */ rtl = rtl_for_decl_init (init, type); if (rtl && !early_dwarf) - return add_const_value_attribute (die, rtl); + return add_const_value_attribute (die, TYPE_MODE (type), rtl); /* If the host and target are sane, try harder. */ if (CHAR_BIT == 8 && BITS_PER_UNIT == 8 && initializer_constant_valid_p (init, type)) Jakub