From patchwork Fri Dec 3 11:46:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Matthias_M=C3=A4nnich?= X-Patchwork-Id: 48461 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 BD8C73858012 for ; Fri, 3 Dec 2021 12:09:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BD8C73858012 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1638533352; bh=1XWGRXqZ2+pcRfDDa8D4tHKgHeIyWg+R7vLOyfeTGsA=; h=Date:In-Reply-To:References:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Help:List-Subscribe:From:Reply-To:Cc:From; b=gPxnPH2rm3F3L7bA4CTK5wWxMaU0+2AynGkZXsVZpQJR3RhMrOXsvQvK1GoRDFUJf 1m51x36dG17yvVuI1xhn2iNW40cwgTmeCA3EaIQ96En/qiGnarKI2eiHKv/1xvUx9U 8pfmHfs9j5e22JuAYRpL0JLzNT2AyXtWwYwhmpPY= X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from mail-ed1-x54a.google.com (mail-ed1-x54a.google.com [IPv6:2a00:1450:4864:20::54a]) by sourceware.org (Postfix) with ESMTPS id 919BC3858D39 for ; Fri, 3 Dec 2021 12:09:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 919BC3858D39 Received: by mail-ed1-x54a.google.com with SMTP id b15-20020aa7c6cf000000b003e7cf0f73daso2343157eds.22 for ; Fri, 03 Dec 2021 04:09:07 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=1XWGRXqZ2+pcRfDDa8D4tHKgHeIyWg+R7vLOyfeTGsA=; b=6ja+1qZ28yxcOCCvah7thcPgqUpGuIeQkJyZzMOOU6dUJ/Kmghl7oCCi7ozzMnKwkp gtAXEDpnLtz2inJJbCXSxIBrmN3IoGCGMiw7mZR08oD3j71FYes/vNM+0yhGe6wg1NSZ tZv08ziPW103xe4u6fHAH5255pYw1U2PXWFqzwkIZkexLagesbeGQRnVyNietxsyRb6o RHKC7jB9eOBZK4qgTVuBUzYtCle0OJcva3OiFTgMg1sekgJw7rlnqVMKC1/2uR65QED3 9FHOFmmonO6pXK0THFL5LKXLYKSm2l9VLU7MpWUCR7jdFMxHbCNYcmv2FlvSKy79atUF 9HXQ== X-Gm-Message-State: AOAM530C311JqxGGlR7L8f2v3uhqY9bfINcfjnKEKWSCnBvBaGXig3Yp EbxIf1MqCgGtwDmD7BRtMh4QNS0cfiVwxpMwYQFsfNOX/0C8i3sfqLa9aTPpTQD7Dq1DK2Oz7Jz YKZ5jC+7PRsvXXadej9UuDSdFT7WGYYtLQ0BOt7cWoIJbJmewvDwUjQhMmrbORPtcP/6eV8Y= X-Google-Smtp-Source: ABdhPJxv1NLQ0+erDaEvteuZ4k73L1HTLL4iJMtymDaDQLhCMo6O2qX0i/XsYKAMgj+CZ0vzoOLW6x4AAhgl9A== X-Received: from lux.lon.corp.google.com ([2a00:79e0:d:210:47e9:78df:690b:201]) (user=maennich job=sendgmr) by 2002:a17:906:52d8:: with SMTP id w24mr23886120ejn.296.1638533346640; Fri, 03 Dec 2021 04:09:06 -0800 (PST) Date: Fri, 3 Dec 2021 11:46:19 +0000 In-Reply-To: <20211203114622.2944173-1-maennich@google.com> Message-Id: <20211203114622.2944173-2-maennich@google.com> Mime-Version: 1.0 References: <20211203114622.2944173-1-maennich@google.com> X-Mailer: git-send-email 2.34.1.400.ga245620fadb-goog Subject: [PATCH 1/5] XML writer: use consistent type pointers for type ids and emission tracking To: libabigail@sourceware.org X-Spam-Status: No, score=-21.6 required=5.0 tests=BAYES_00, DKIMWL_WL_MED, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, USER_IN_DEF_DKIM_WL 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: libabigail@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list of the Libabigail project List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-Patchwork-Original-From: Matthias Maennich via Libabigail From: =?utf-8?q?Matthias_M=C3=A4nnich?= Reply-To: Matthias Maennich Cc: maennich@google.com, kernel-team@android.com Errors-To: libabigail-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libabigail" Insertion resolves the canonical type, if available, but look-up did not. Given that type id insertion and look-up also resolve canonical types, it makes sense to adjust the remaining code accordingly. Neither decl_only_type_is_emitted nor record_decl_only_type_as_emitted do the check, but very few types end up being recorded this way. The functions write_class_decl and write_union_decl (but not write_class_decl_opening_tag and write_union_decl_opening_tag which can be called in other contexts) resolve declaration-only types to a definition where possible. To ensure type ids consistently refer to the same resolved type we should resolve canonical types and definitions-of-declarations more consistently. This change introduces get_preferred_type to return the exemplar type that should be used for type id and emitted checks. However, it does not also change all the write functions to write out the exemplar types. * src/abg-writer.cc (get_preferred_type): new function. (type_has_existing_id): use get_preferred_type for resolution. (get_id_for_type): Likewise. (record_type_as_emitted): Likewise. (type_is_emitted): Likewise. Reviewed-by: Giuliano Procida Signed-off-by: Matthias Maennich Reviewed-by: Giuliano Procida Signed-off-by: Matthias Maennich Signed-off-by: Dodji Seketeli --- src/abg-writer.cc | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/src/abg-writer.cc b/src/abg-writer.cc index 21b79e888f31..9c3ae6f8d5b4 100644 --- a/src/abg-writer.cc +++ b/src/abg-writer.cc @@ -390,14 +390,25 @@ public: type_has_existing_id(type_base_sptr type) const {return type_has_existing_id(type.get());} + type_base* + get_preferred_type(const type_base* type) const + { + // declaration -> definition -> canonical is possible + if (decl_base* decl = look_through_decl_only(is_decl(type))) + { + type = is_type(decl); + ABG_ASSERT(type); + } + type_base* canonical = type->get_naked_canonical_type(); + return canonical ? canonical : const_cast(type); + } + /// @return true iff type has already been assigned an ID. bool type_has_existing_id(type_base* type) const { - type_base *c = type->get_naked_canonical_type(); - if (c == 0) - c = const_cast(type); - return (m_type_id_map.find(c) != m_type_id_map.end()); + type = get_preferred_type(type); + return m_type_id_map.find(type) != m_type_id_map.end(); } /// Associate a unique id to a given type. For that, put the type @@ -413,11 +424,9 @@ public: /// associated to it, create a new one and return it. Otherwise, /// return the existing id for that type. interned_string - get_id_for_type(const type_base* t) const + get_id_for_type(type_base* type) const { - type_base *c = t->get_naked_canonical_type(); - if (c == 0) - c = const_cast(t); + type_base* c = get_preferred_type(type); type_ptr_map::const_iterator it = m_type_id_map.find(c); if (it != m_type_id_map.end()) @@ -715,11 +724,9 @@ public: /// /// @param t the type to flag. void - record_type_as_emitted(const type_base *t) + record_type_as_emitted(const type_base* t) { - type_base *c = t->get_naked_canonical_type(); - if (c == 0) - c = const_cast(t); + type_base* c = get_preferred_type(t); m_emitted_type_set.insert(c); } @@ -730,9 +737,10 @@ public: /// @return true if the type has already been emitted, false /// otherwise. bool - type_is_emitted(const type_base *t) const + type_is_emitted(const type_base* t) const { - return m_emitted_type_set.find(t) != m_emitted_type_set.end(); + type_base* c = get_preferred_type(t); + return m_emitted_type_set.find(c) != m_emitted_type_set.end(); } /// Test if a given type has been written out to the XML output.