From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by sourceware.org (Postfix) with ESMTPS id F07473982007 for ; Thu, 15 Jul 2021 12:10:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org F07473982007 Received: by mail-ej1-x62b.google.com with SMTP id hd33so8857289ejc.9 for ; Thu, 15 Jul 2021 05:10:06 -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=Q1jEa2f2n56TDcXJjFHr4BlX9YPIT7Nqd5oUTTw16/U=; b=Jm9B0n3MJQpGmTnspOxhLyZYH6wiCucvmqlDvDzrKn2ZCJC/WIczT+Jop3b+YIqXJM 0YWlV0Ja+XVqhpmqqB88LTRayMwCDKSfMQRm9yIVbRJ5f1nO30l/X5l4y4qwN+ha2j1/ nsEuy5WPrQnDeI/D0XT3q/hSdVGhg8vnPcYtcxU883GvL5Umw553f0GxL5dBdfS8yh2Z zk0a+rmOxo0BS5gt9W90yY2pEhoTz0ZtB8Y8P2D2BfzVTbdXEtGc20/KWSfI5bHPvmy1 lI+6m0T8TGr2Qt+57CePQ9FNGQOWfKcp/5SjyVi8yhQgzYUuDfA6sKHHtHQZx45Nu1GM Mq5w== X-Gm-Message-State: AOAM530vxQW429/VYIYD7WGajt4Tn0urXImhmYK9q9TNGPBjU+I75gHv HdQAz5RcB/YRXcsBwco5IL1fKPUVQo3Q7J3cJbA= X-Google-Smtp-Source: ABdhPJxU6PJ6Rf4VMyHbAE7D/Xeso05v8gRoRr5RZhF4zNtF0MF6R3xVFkmbKOPAFQgz+jYfs8htIXk3A0vLipePLCw= X-Received: by 2002:a17:906:4a0a:: with SMTP id w10mr5272366eju.371.1626351006073; Thu, 15 Jul 2021 05:10:06 -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: <50d1657e-c5de-9cb9-1aaa-233f27dfe9b9@mentor.com> From: Richard Biener Date: Thu, 15 Jul 2021 14:09:55 +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.6 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: Thu, 15 Jul 2021 12:10:08 -0000 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. > > -- > Hafiz Abid Qadeer > Mentor, a Siemens Business