From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by sourceware.org (Postfix) with ESMTPS id 4A7AD385DC2B for ; Mon, 19 Jul 2021 10:45:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4A7AD385DC2B Received: by mail-ej1-x62f.google.com with SMTP id go30so27905645ejc.8 for ; Mon, 19 Jul 2021 03:45:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=0r0gsLoUr+k3Mj15vos02azftiPzslBFRLcSyVReX2Q=; b=UBu/2Uex0nREa1G2gbFWqtAYoorf4ARV55KMSyiTYzUWqbrMB/rEy0U6xLzezWNSS+ R8hjMovEPpyaM2dtBkX5X7nu2MrdhmD6VpZ5JHg19XhZUyAZvLBDZmO8CTqWjAYpq+iz kYBHjtZRkPRJ0MnJLZ+XU1TqDd51ebMjpihWvaIj8WL+nwi9zq17sEE6uX7h/kvqaw4L lkS2Gum2d2T1FjAiqAdniTvopIfPjjdvtqs5s4aScSmt2GJ6YfgU3htRCjItPOBWStNi MXvdtZCmjhXRUcPchzEmBn8gONOtRnX9srAy9gRICp4wGG2IhNKUvRXkHHqn9RPnOaOu fmLw== X-Gm-Message-State: AOAM5305XXpWmymN/cbY4RcptTBYZRoP/Ty1E9fVtAdhwe5hugoDWY6U N0IULkElxXqCkrLFZ4gvgpb1vx8RndNWjh19+DM= X-Google-Smtp-Source: ABdhPJze4sdTnwEgsvlEh+v2Bd31kN+clCvg0jFA+aGcfx0rXWtZE+0TDXWBn8tHDA2ZkOUjB9nPMah1mTZqlLfi39o= X-Received: by 2002:a17:906:dfdb:: with SMTP id jt27mr27542969ejc.138.1626691534629; Mon, 19 Jul 2021 03:45:34 -0700 (PDT) MIME-Version: 1.0 References: <20210701151657.935006-1-abidh@codesourcery.com> <8735sfamu7.fsf@dem-tschwing-1.ger.mentorg.com> <50d1657e-c5de-9cb9-1aaa-233f27dfe9b9@mentor.com> In-Reply-To: From: Richard Biener Date: Mon, 19 Jul 2021 12:45:23 +0200 Message-ID: Subject: Re: [PATCH] [DWARF] Fix hierarchy of debug information for offload kernels. To: Hafiz Abid Qadeer Cc: Thomas Schwinge , Abid Qadeer , Jakub Jelinek , GCC Patches Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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: Mon, 19 Jul 2021 10:45:38 -0000 On Fri, Jul 16, 2021 at 10:23 PM Hafiz Abid Qadeer wrote: > > On 15/07/2021 13:09, Richard Biener wrote: > > On Thu, Jul 15, 2021 at 12:35 PM Hafiz Abid Qadeer > > wrote: > >> > >> On 15/07/2021 11:33, Thomas Schwinge wrote: > >>> > >>>> Note that the "parent" should be abstract but I don't think dwarf has a > >>>> way to express a fully abstract parent of a concrete instance child - or > >>>> at least how GCC expresses this causes consumers to "misinterpret" > >>>> that. I wonder if adding a DW_AT_declaration to the late DWARF > >>>> emitted "parent" would fix things as well here? > >>> > >>> (I suppose not, Abid?) > >>> > >> > >> Yes, adding DW_AT_declaration does not fix the problem. > > > > Does emitting > > > > DW_TAG_compile_unit > > DW_AT_name ("") > > > > DW_TAG_subprogram // notional parent function (foo) with no code range > > DW_AT_declaration 1 > > a: DW_TAG_subprogram // offload function foo._omp_fn.0 > > DW_AT_declaration 1 > > > > DW_TAG_subprogram // offload function > > DW_AT_abstract_origin a > > ... > > > > do the trick? The following would do this, flattening function definitions > > for the concrete copies: > > > > diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c > > index 82783c4968b..a9c8bc43e88 100644 > > --- a/gcc/dwarf2out.c > > +++ b/gcc/dwarf2out.c > > @@ -6076,6 +6076,11 @@ maybe_create_die_with_external_ref (tree decl) > > /* Peel types in the context stack. */ > > while (ctx && TYPE_P (ctx)) > > ctx = TYPE_CONTEXT (ctx); > > + /* For functions peel the context up to namespace/TU scope. The abstract > > + copies reveal the true nesting. */ > > + if (TREE_CODE (decl) == FUNCTION_DECL) > > + while (ctx && TREE_CODE (ctx) == FUNCTION_DECL) > > + ctx = DECL_CONTEXT (ctx); > > /* Likewise namespaces in case we do not want to emit DIEs for them. */ > > if (debug_info_level <= DINFO_LEVEL_TERSE) > > while (ctx && TREE_CODE (ctx) == NAMESPACE_DECL) > > @@ -6099,8 +6104,7 @@ maybe_create_die_with_external_ref (tree decl) > > /* Leave function local entities parent determination to when > > we process scope vars. */ > > ; > > - else > > - parent = lookup_decl_die (ctx); > > + parent = lookup_decl_die (ctx); > > } > > else > > /* In some cases the FEs fail to set DECL_CONTEXT properly. > > > > Thanks. This solves the problem. Only the first hunk was required. Second hunk > actually causes an ICE when TREE_CODE (ctx) == BLOCK. > OK to commit the attached patch? I think we need to merge the TYPE_P peeling and FUNCTION_DECL peeling into one loop since I suppose we can have a nested function in class scope. So sth like diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c index 82783c4968b..61228410b51 100644 --- a/gcc/dwarf2out.c +++ b/gcc/dwarf2out.c @@ -6073,8 +6073,12 @@ maybe_create_die_with_external_ref (tree decl) } else ctx = DECL_CONTEXT (decl); - /* Peel types in the context stack. */ - while (ctx && TYPE_P (ctx)) + /* Peel types in the context stack. For functions peel the context up + to namespace/TU scope. The abstract copies reveal the true nesting. */ + while (ctx + && (TYPE_P (ctx) + || (TREE_CODE (decl) == FUNCTION_DECL + && TREE_CODE (ctx) == FUNCTION_DECL))) ctx = TYPE_CONTEXT (ctx); /* Likewise namespaces in case we do not want to emit DIEs for them. */ if (debug_info_level <= DINFO_LEVEL_TERSE) if that works it's OK. Can you run it on the gdb testsuite with -flto added as well please (you need to do before/after comparison since IIRC adding -flto will add a few fails). Thanks, Richard.