From patchwork Sat May 1 17:55:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 1472650 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=adacore-com.20150623.gappssmtp.com header.i=@adacore-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=mqc8+c93; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FXcP848FJz9sWD for ; Sun, 2 May 2021 03:56:26 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 336CD388E828; Sat, 1 May 2021 17:56:24 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by sourceware.org (Postfix) with ESMTPS id 797D2385800A for ; Sat, 1 May 2021 17:56:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 797D2385800A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=botcazou@adacore.com Received: by mail-wm1-x335.google.com with SMTP id g65so878779wmg.2 for ; Sat, 01 May 2021 10:56:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=1pJmu9canPx7ihkMRKi6sA8aWUwjno8J12dfskKqQ5E=; b=mqc8+c9306hEC+bV1M/2R6EYppdQlB0tx/AyjfKyhR5Iq9gHp7Qlv29bkfh96FMUrR BfljLaaeqcu8dRND+GmkkyI1NXGTNZ8gWAMVfWHPiZTRmM3qWRhGNG1vk2HqDnshv4BB Sp2ePGSfFKeodoPQzymY9e4jxiN9U9S8xFd8VKykp1mGwgJBQhsJkuRMdZvkUr/7AL1V Y90em6fZoca04Pqvk+QfhwxPBtEtigniR1up9vk1mXG7RyxA8uVLupwTRMO80bOXMoHZ qPTyFiX3RIl4Oba6BxAAXkhs4y65HQpqlDHsD5YUCb0De2+s05FW+uieJ/ioWHcz9VbO Tzow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=1pJmu9canPx7ihkMRKi6sA8aWUwjno8J12dfskKqQ5E=; b=gAJFqqPCLWpnt7rfmA9zc/S+USTQMWhhpQe0Rw/xE+RVB0Yvg9JwVgQZP+CVF/P4CO sLCyEN67ViWnO+nDXI+bTX0BLhPAGe43LQlgF0Vv1NqxVnUfkm9fy9z+uEdR6FrJEAJa sQ2tufu8v84UeKFJsqyqv4TL0udKXRBMTmLKRIVwgVVOpwbFKJGveqMpDcw52SIrPJIG LKEsLsUb0WUokbCB3xOb1aZaNOYmtNnzrUQUGtElqmBNVS1lrk0lqJVJORe8h9BnmGbH hdcX/esc5MI6aHlAhqoklcYFF4pFy7V+sufZ7EeMikRb3OLAXTs3Cp+IaFIJHQN/IG0n Chvg== X-Gm-Message-State: AOAM530Qn5yCvHx5fj4UBdy6gJnS8o+G/r3ZeUb0FMP7Ol18lJLAnjKw kpNWaubOmhPQVE/TGyAwu0yg5KB6BFeYyD+q X-Google-Smtp-Source: ABdhPJyBjVGtluV7VN1PaIpl2MokpUVLWrgnhgXf/tiSYT2MROtj57+LCgcvKOy7uMpcXtigbW4fMA== X-Received: by 2002:a05:600c:3643:: with SMTP id y3mr22619581wmq.159.1619891780127; Sat, 01 May 2021 10:56:20 -0700 (PDT) Received: from fomalhaut.localnet ([2a01:e0a:41b:84f0:cf71:f5e0:b050:bede]) by smtp.gmail.com with ESMTPSA id o1sm6733494wrm.66.2021.05.01.10.56.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 May 2021 10:56:19 -0700 (PDT) From: Eric Botcazou X-Google-Original-From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [patch] Generate debug info for local dynamic record types Date: Sat, 01 May 2021 19:55:47 +0200 Message-ID: <2787529.e9J7NaK4W3@fomalhaut> MIME-Version: 1.0 X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: , Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Hi, in Ada you can embed VLAs in local record types and thus end up with dynamic offsets in record types, which are currently not well described in DWARF because 1) the temporaries generated for them by the gimplifier are naturally DECL_IGNORED_P and 2) when the types are referenced in nested subprograms, the DWARF back-end does not correctly handle the rewritten references. The attached patch fixes 1) by reusing the trick already used for VLAs and 2) by deferring the resolution of these references to the late DWARF pass. Tested on x86-64/Linux, both GCC and GDB, OK for the mainline? 2021-05-01 Eric Botcazou * dwarf2out.c (loc_list_from_tree_1) : During early DWARF, do not expand the VALUE_EXPR of variables put in the non-local frame. * gimplify.c (gimplify_type_sizes) : If the type is not to be ignored for debug info, ensure its variable offsets are not either. diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c index c36fd5a7f6a..5b819ab1a92 100644 --- a/gcc/dwarf2out.c +++ b/gcc/dwarf2out.c @@ -18658,8 +18658,20 @@ loc_list_from_tree_1 (tree loc, int want_address, case RESULT_DECL: if (DECL_HAS_VALUE_EXPR_P (loc)) - return loc_list_from_tree_1 (DECL_VALUE_EXPR (loc), - want_address, context); + { + tree value_expr = DECL_VALUE_EXPR (loc); + + /* Non-local frame structures are DECL_IGNORED_P variables so we need + to wait until they get an RTX in order to reference them. */ + if (early_dwarf + && TREE_CODE (value_expr) == COMPONENT_REF + && VAR_P (TREE_OPERAND (value_expr, 0)) + && DECL_NONLOCAL_FRAME (TREE_OPERAND (value_expr, 0))) + ; + else + return loc_list_from_tree_1 (value_expr, want_address, context); + } + /* FALLTHRU */ case FUNCTION_DECL: diff --git a/gcc/gimplify.c b/gcc/gimplify.c index b65106b1459..e790f08b23f 100644 --- a/gcc/gimplify.c +++ b/gcc/gimplify.c @@ -15141,11 +15141,15 @@ gimplify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p, void gimplify_type_sizes (tree type, gimple_seq *list_p) { - tree field, t; - if (type == NULL || type == error_mark_node) return; + const bool ignored_p + = TYPE_NAME (type) + && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL + && DECL_IGNORED_P (TYPE_NAME (type)); + tree t; + /* We first do the main variant, then copy into any other variants. */ type = TYPE_MAIN_VARIANT (type); @@ -15179,9 +15183,7 @@ gimplify_type_sizes (tree type, gimple_seq *list_p) /* Ensure VLA bounds aren't removed, for -O0 they should be variables with assigned stack slots, for -O1+ -g they should be tracked by VTA. */ - if (!(TYPE_NAME (type) - && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL - && DECL_IGNORED_P (TYPE_NAME (type))) + if (!ignored_p && TYPE_DOMAIN (type) && INTEGRAL_TYPE_P (TYPE_DOMAIN (type))) { @@ -15197,10 +15199,16 @@ gimplify_type_sizes (tree type, gimple_seq *list_p) case RECORD_TYPE: case UNION_TYPE: case QUAL_UNION_TYPE: - for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field)) + for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field)) if (TREE_CODE (field) == FIELD_DECL) { gimplify_one_sizepos (&DECL_FIELD_OFFSET (field), list_p); + /* Likewise, ensure variable offsets aren't removed. */ + if (!ignored_p + && (t = DECL_FIELD_OFFSET (field)) + && VAR_P (t) + && DECL_ARTIFICIAL (t)) + DECL_IGNORED_P (t) = 0; gimplify_one_sizepos (&DECL_SIZE (field), list_p); gimplify_one_sizepos (&DECL_SIZE_UNIT (field), list_p); gimplify_type_sizes (TREE_TYPE (field), list_p);