From patchwork Tue Feb 8 08:07:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 50905 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 407F33858402 for ; Tue, 8 Feb 2022 08:07:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 407F33858402 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1644307667; bh=cI0mp71QZ3HIvrKhgjM6tBLae9Y1lAD82KsNUjXkDEM=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=Pm642ggkz+JLJNNiQ1i+/WgnjANT0O/HsQHttyDSrh7cB1uZnPLj+NzvDem06RTuN ryC/oImG/CE4fh07jeUIiyn138tcftNNMuM1rbPZa5a1yuput8xSQcsd3XoJLaWhEn k40w/uGr6JvdC9/URXFJXWoeT26k9wnFIPkpT9Us= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id D3F793858C27 for ; Tue, 8 Feb 2022 08:07:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D3F793858C27 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-504-ag0RFuXgMDqSygQFybQiig-1; Tue, 08 Feb 2022 03:07:12 -0500 X-MC-Unique: ag0RFuXgMDqSygQFybQiig-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4DFA4190A7A9; Tue, 8 Feb 2022 08:07:11 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.125]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D53D95E4A6; Tue, 8 Feb 2022 08:07:10 +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 218877p13380399 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 8 Feb 2022 09:07:08 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.16.1/8.16.1/Submit) id 218877OL3380398; Tue, 8 Feb 2022 09:07:07 +0100 Date: Tue, 8 Feb 2022 09:07:06 +0100 To: Richard Biener , Jason Merrill Subject: [PATCH] dwarf2out: Don't call expand_expr during early_dwarf [PR104407] Message-ID: <20220208080706.GB2646553@tucnak> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-5.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Hi! As mentioned in the PR, since PR96690 r11-2834 we call rtl_for_decl_init which can call expand_expr already during early_dwarf. The comment and PR explains it that the intent is to ensure the referenced vars and functions are properly mangled because free_lang_data doesn't cover everything, like template parameters etc. It doesn't work well though, because expand_expr can set DECL_RTLs e.g. on referenced vars and keep them there, and they can be created e.g. with different MEM_ALIGN compared to what they would be created with if they were emitted later. So, the following patch stops calling rtl_for_decl_init and instead for cases for which rtl_for_decl_init does anything at all walks the initializer and ensures referenced vars or functions are mangled. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2022-02-08 Jakub Jelinek PR debug/104407 * dwarf2out.cc (mangle_referenced_decls): New function. (tree_add_const_value_attribute): Don't call rtl_for_decl_init if early_dwarf. Instead walk the initializer and try to mangle vars or functions referenced from it. * g++.dg/debug/dwarf2/pr104407.C: New test. Jakub --- gcc/dwarf2out.cc.jj 2022-02-04 14:36:54.966605844 +0100 +++ gcc/dwarf2out.cc 2022-02-07 12:28:13.000520666 +0100 @@ -20881,6 +20881,19 @@ add_location_or_const_value_attribute (d return tree_add_const_value_attribute_for_decl (die, decl); } +/* Mangle referenced decls. */ +static tree +mangle_referenced_decls (tree *tp, int *walk_subtrees, void *) +{ + if (! EXPR_P (*tp) && ! CONSTANT_CLASS_P (*tp)) + *walk_subtrees = 0; + + if (VAR_OR_FUNCTION_DECL_P (*tp)) + assign_assembler_name_if_needed (*tp); + + return NULL_TREE; +} + /* Attach a DW_AT_const_value attribute to DIE. The value of the attribute is the const value T. */ @@ -20889,7 +20902,6 @@ tree_add_const_value_attribute (dw_die_r { tree init; tree type = TREE_TYPE (t); - rtx rtl; if (!t || !TREE_TYPE (t) || TREE_TYPE (t) == error_mark_node) return false; @@ -20910,11 +20922,26 @@ tree_add_const_value_attribute (dw_die_r return true; } } - /* Generate the RTL even if early_dwarf to force mangling of all refered to - symbols. */ - rtl = rtl_for_decl_init (init, type); - if (rtl && !early_dwarf) - return add_const_value_attribute (die, TYPE_MODE (type), rtl); + if (!early_dwarf) + { + rtx rtl = rtl_for_decl_init (init, type); + if (rtl && !early_dwarf) + return add_const_value_attribute (die, TYPE_MODE (type), rtl); + } + else + { + /* For early_dwarf force mangling of all referenced symbols. */ + tree initializer = init; + STRIP_NOPS (initializer); + /* rtl_for_decl_init punts on other aggregates, and complex values. */ + if (AGGREGATE_TYPE_P (type) + || (TREE_CODE (initializer) == VIEW_CONVERT_EXPR + && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (initializer, 0)))) + || TREE_CODE (type) == COMPLEX_TYPE) + ; + else if (initializer_constant_valid_p (initializer, type)) + walk_tree (&initializer, mangle_referenced_decls, NULL, NULL); + } /* If the host and target are sane, try harder. */ if (CHAR_BIT == 8 && BITS_PER_UNIT == 8 && initializer_constant_valid_p (init, type)) --- gcc/testsuite/g++.dg/debug/dwarf2/pr104407.C.jj 2022-02-07 10:45:51.945041031 +0100 +++ gcc/testsuite/g++.dg/debug/dwarf2/pr104407.C 2022-02-07 10:45:09.834635340 +0100 @@ -0,0 +1,12 @@ +// PR debug/104407 +// { dg-do compile { target c++17 } } +// { dg-options "-O1 -fcompare-debug" } + +struct A { int i; long j; int k : 2; char l; } a; + +auto [ aa, bb, cc, dd ] = a; + +namespace N +{ + auto & [ m, n, o, ppp ] = a; +}