From patchwork Fri Mar 25 11:37:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 1609394 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=aG352f3I; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4KQ0Tt4LCzz9s0B for ; Fri, 25 Mar 2022 22:38:42 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B858B3851C02 for ; Fri, 25 Mar 2022 11:38:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B858B3851C02 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1648208320; bh=CinzBmbNB/i/StWCubJFSD8T9uaQ1/9xtXh+YTyHh94=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=aG352f3IfMGT/JUTFEfNZLgtDXPyP1w+N+yHpDp9QrLfeaZWmfBPiSxmxQjoQ2adW iUrAKw7Q2aR6FaRxUF9ewwPSgZdFkDnx3hw4m84+wEF0owWjM+PJ8KaYzfp9p17HSU 5JzjaxHF++9nNe1LIGURWDCi+dm/HJfkCWHkd1Wg= 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 81E2F3857404 for ; Fri, 25 Mar 2022 11:37:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 81E2F3857404 Received: by mail-wm1-x335.google.com with SMTP id r190-20020a1c2bc7000000b0038a1013241dso4224719wmr.1 for ; Fri, 25 Mar 2022 04:37:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=CinzBmbNB/i/StWCubJFSD8T9uaQ1/9xtXh+YTyHh94=; b=nusCTbMmygzOOthesxFwwLU4hqgTP7W9oIFoEwkUgzOwznqUQyiCEM+GO6aMHuIA5r VUUj+mc/cj1eTNT0s13pAh79A5bIykD4fFYM8TvjfIPVUYKr93Bv4y8UFr0ttwmt6Y5+ aslZcvcrTcSRsrs4t6xzyZQR/sREkXzLELiBfdpMee+idu3GMDScxh72LDyqe1zT9s++ iGB6Ypdb2OVz71fkelokvr5EmTCfrJmbrObozQgE5smR98qiXglndnSV0ZdVsxop3K2y B9xmEDv6T9T4au3MQKJRE+/p/OR3r/kmU3OXdaZlTlvvWyyZU6dczU5fcLP/u8q/oFpD d3dQ== X-Gm-Message-State: AOAM531KNgxRbdUozHdEtGYaMl84dz+1HFK/amcNqLROUfc/F8IwnSLz CriSNufUuhO9hdweN6rRrlFMLmwxzAPaqg== X-Google-Smtp-Source: ABdhPJypEXt99GA9KOL7nMfUy4jy+YlbjEp3FOFipVRxsgoiyYZFFZEkgvBw0OlsDd+KUb86JwNpIg== X-Received: by 2002:a05:600c:35cc:b0:38c:6d25:f4ad with SMTP id r12-20020a05600c35cc00b0038c6d25f4admr9395190wmq.127.1648208277192; Fri, 25 Mar 2022 04:37:57 -0700 (PDT) Received: from fomalhaut.localnet ([2a01:e0a:41b:84f0:cf71:f5e0:b050:bede]) by smtp.gmail.com with ESMTPSA id r14-20020a05600c35ce00b0038c9f469979sm4314066wmq.40.2022.03.25.04.37.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Mar 2022 04:37:56 -0700 (PDT) X-Google-Original-From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [c-family] Fix issue for pointers to anonymous types with -fdump-ada-spec Date: Fri, 25 Mar 2022 12:37:55 +0100 Message-ID: <3160640.aeNJFYEL58@fomalhaut> MIME-Version: 1.0 X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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: Eric Botcazou via Gcc-patches From: Eric Botcazou Reply-To: Eric Botcazou Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" This used to work long ago but broke at some point, so I'm applying the fix only on the mainline, all the more so that it deals the "section" attribute. Tested on x86-64/Linux, applied on the mainline. 2022-03-25 Eric Botcazou c-family/ * c-ada-spec.cc (dump_ada_import): Deal with the "section" attribute. (dump_ada_node) : Do not modify and pass the name, but the referenced type instead. Deal with the anonymous original type of a typedef'ed type. In the actual access case, follow the chain of external subtypes. : Tidy up control flow. diff --git a/gcc/c-family/c-ada-spec.cc b/gcc/c-family/c-ada-spec.cc index aeb429136b6..f291e150934 100644 --- a/gcc/c-family/c-ada-spec.cc +++ b/gcc/c-family/c-ada-spec.cc @@ -1526,6 +1526,15 @@ dump_ada_import (pretty_printer *buffer, tree t, int spc) newline_and_indent (buffer, spc + 5); + tree sec = lookup_attribute ("section", DECL_ATTRIBUTES (t)); + if (sec) + { + pp_string (buffer, "Linker_Section => \""); + pp_string (buffer, TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (sec)))); + pp_string (buffer, "\", "); + newline_and_indent (buffer, spc + 5); + } + pp_string (buffer, "External_Name => \""); if (is_stdcall) @@ -2179,10 +2188,11 @@ dump_ada_node (pretty_printer *buffer, tree node, tree type, int spc, } else { - const unsigned int quals = TYPE_QUALS (TREE_TYPE (node)); + tree ref_type = TREE_TYPE (node); + const unsigned int quals = TYPE_QUALS (ref_type); bool is_access = false; - if (VOID_TYPE_P (TREE_TYPE (node))) + if (VOID_TYPE_P (ref_type)) { if (!name_only) pp_string (buffer, "new "); @@ -2197,9 +2207,8 @@ dump_ada_node (pretty_printer *buffer, tree node, tree type, int spc, else { if (TREE_CODE (node) == POINTER_TYPE - && TREE_CODE (TREE_TYPE (node)) == INTEGER_TYPE - && id_equal (DECL_NAME (TYPE_NAME (TREE_TYPE (node))), - "char")) + && TREE_CODE (ref_type) == INTEGER_TYPE + && id_equal (DECL_NAME (TYPE_NAME (ref_type)), "char")) { if (!name_only) pp_string (buffer, "new "); @@ -2214,28 +2223,11 @@ dump_ada_node (pretty_printer *buffer, tree node, tree type, int spc, } else { - tree type_name = TYPE_NAME (TREE_TYPE (node)); - - /* Generate "access " instead of "access " - if the subtype comes from another file, because subtype - declarations do not contribute to the limited view of a - package and thus subtypes cannot be referenced through - a limited_with clause. */ - if (type_name - && TREE_CODE (type_name) == TYPE_DECL - && DECL_ORIGINAL_TYPE (type_name) - && TYPE_NAME (DECL_ORIGINAL_TYPE (type_name))) - { - const expanded_location xloc - = expand_location (decl_sloc (type_name, false)); - if (xloc.line - && xloc.file - && xloc.file != current_source_file) - type_name = DECL_ORIGINAL_TYPE (type_name); - } + tree stub = TYPE_STUB_DECL (ref_type); + tree type_name = TYPE_NAME (ref_type); /* For now, handle access-to-access as System.Address. */ - if (TREE_CODE (TREE_TYPE (node)) == POINTER_TYPE) + if (TREE_CODE (ref_type) == POINTER_TYPE) { if (package_prefix) { @@ -2251,7 +2243,7 @@ dump_ada_node (pretty_printer *buffer, tree node, tree type, int spc, if (!package_prefix) pp_string (buffer, "access"); - else if (AGGREGATE_TYPE_P (TREE_TYPE (node))) + else if (AGGREGATE_TYPE_P (ref_type)) { if (!type || TREE_CODE (type) != FUNCTION_DECL) { @@ -2281,12 +2273,41 @@ dump_ada_node (pretty_printer *buffer, tree node, tree type, int spc, pp_string (buffer, "all "); } - if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (node)) && type_name) - dump_ada_node (buffer, type_name, TREE_TYPE (node), spc, - is_access, true); - else - dump_ada_node (buffer, TREE_TYPE (node), TREE_TYPE (node), - spc, false, true); + /* If this is the anonymous original type of a typedef'ed + type, then use the name of the latter. */ + if (!type_name + && stub + && DECL_CHAIN (stub) + && TREE_CODE (DECL_CHAIN (stub)) == TYPE_DECL + && DECL_ORIGINAL_TYPE (DECL_CHAIN (stub)) == ref_type) + ref_type = TREE_TYPE (DECL_CHAIN (stub)); + + /* Generate "access " instead of "access " + if the subtype comes from another file, because subtype + declarations do not contribute to the limited view of a + package and thus subtypes cannot be referenced through + a limited_with clause. */ + else if (is_access) + while (type_name + && TREE_CODE (type_name) == TYPE_DECL + && DECL_ORIGINAL_TYPE (type_name) + && TYPE_NAME (DECL_ORIGINAL_TYPE (type_name))) + { + const expanded_location xloc + = expand_location (decl_sloc (type_name, false)); + if (xloc.line + && xloc.file + && xloc.file != current_source_file) + { + ref_type = DECL_ORIGINAL_TYPE (type_name); + type_name = TYPE_NAME (ref_type); + } + else + break; + } + + dump_ada_node (buffer, ref_type, ref_type, spc, is_access, + true); } } } @@ -2361,10 +2382,8 @@ dump_ada_node (pretty_printer *buffer, tree node, tree type, int spc, else pp_string (buffer, "address"); } - break; } - - if (name_only) + else if (name_only) dump_ada_decl_name (buffer, node, limited_access); else {