From patchwork Fri Sep 25 21:06:05 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dodji Seketeli X-Patchwork-Id: 144683 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 94E404B920F8 for ; Fri, 25 Sep 2026 21:06:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 94E404B920F8 X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) by sourceware.org (Postfix) with ESMTPS id F31FE4B920B4 for ; Fri, 25 Sep 2026 21:06:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F31FE4B920B4 Authentication-Results: sourceware.org; dmarc=fail (p=quarantine dis=none) header.from=seketeli.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=seketeli.net ARC-Filter: OpenARC Filter v1.0.0 sourceware.org F31FE4B920B4 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=217.70.183.195 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1790370373; cv=none; b=BtvDALd8Dc/8/15HXIcdnVT4wR58U0BWmgk4uEpki3E3flXg5oMrn+qMg6T35Lg6bcsvRxTYkf9m1LM4YnqeQsBJ4bcYSsjXnbIjowyQIcEzK+xq940mhRENwItOziv/LARdce1p3LYkoWaVyJAzszd5uUKE3KtBUcLgssSsCZM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1790370373; c=relaxed/simple; bh=CaxlB97zhjZhowbmmbmaaRSk+o4IZqXOvEYi0109MU8=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=CTK3ea90tgK2b4FQ8NgvbBOb+6ruX3u192GQna/70jcp6yhbK3fB0AFuXQElTK6oRR7HkAU8j6XxWlfb5umSglOXtGfm6HaPZ9X1gYaVh8ZGsdF+2fzV+4f3zE/KyU8g9SKfi+bOfd8s+nY7dYyi5ZMZyJrLX/op9tKVqdBnYys= ARC-Authentication-Results: i=1; sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F31FE4B920B4 Received: by mail.gandi.net (Postfix) with ESMTPSA id AA15C1F47F for ; Fri, 25 Sep 2026 21:06:09 +0000 (UTC) Received: by localhost (Postfix, from userid 1000) id B1FF4603B6B1; Fri, 25 Sep 2026 23:06:08 +0200 (CEST) From: Dodji Seketeli To: libabigail@sourceware.org Subject: [PATCH 11/14] ir: Fix adding a canonical type to its homonym type group Date: Fri, 25 Sep 2026 23:06:05 +0200 Message-ID: <20260925210608.3532891-12-dodji@seketeli.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260925210608.3532891-1-dodji@seketeli.org> References: <20260925210608.3532891-1-dodji@seketeli.org> MIME-Version: 1.0 X-GND-Sasl: dodj@seketeli.net X-GND-Score: 0 X-GND-Cause: dmFkZTG26MAA5sz4HHSDFWSn2yXJuxOcGE0n1OO2ldtGXUUMTqLkL5RqRxKBM3dzphI2TJybTCOsNWNG2D5EYamv45EHhxwCPemb1YxyEPoQm0exgrwYJOeAd6CNdE/4gZlfkX2GsvmH1sHX/zSmZZwjAhJki3alhSRP1ObjHpk1wQ8CC02ciVl/ugNN0gvQIor2bWQhzvHrd9UXwxPA9UaiLUw55KXEvwN4yfK16MBpH2nDzGUt4UU0mj9osaIKiRy+Rc9nKGZgJogVnyMo3VCnHmRe/g6R8AzTa+3EgzI0mr+iPbyyNV6ck3/59BEjY1i5jn0vIYFo1U1nsxnC6CDZGjwoiYBplVJh6Az6L1K9kZULydvvZaXwFqyXymLJRqDW7/vXyZNW28svsXJqMCIYJLkVTMJz66PILyLrCR0bcBoRayvBptu3NEE8zOD0HbYz+1i0vHAO7W7LhmyeqYZwAYbtUuUWxwboR6I0Nxcb43EJCr0AedPVik15048GOPL4e7mXetUrRBJS+73xvpgmx9Dd6u2wRhj2urLPBdEgcTpg2Sb2Ky9Deb2f8Li6+1HKX0GjcHTYVgM6hoRQ0mpVwmAq/38vq4j7S0WASBhLgDyNqY1DQUrkoeYOARFE2V71rkkA6pfuwvr5DrpFePJO5/sQ+9N00uYY6QdmYdeWglwijg X-GND-State: clean X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, LOCAL_AUTHENTICATION_FAIL_DMARC, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_PASS, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: libabigail@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Mailing list of the Libabigail project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libabigail-bounces~patchwork=sourceware.org@sourceware.org When looking at some performance issues, I realized that homonym_type_group::add_canonical_type could in theory duplicate canonical types in its homonym_type_group::canonical_types_ data members because it fails to update the homonym_type_group::canonical_types_set_ data member. This patch fixes that. The patch also uses the fixed homonym_type_group::add_canonical_type in homonym_type_group::get_canonical_type_for, instead of poorly open-coding the updating of homonym_type_group::canonical_types_. Incidentally, this ensures that type_base::priv::group is updated by homonym_type_group::get_canonical_type_for. * src/abg-ir-priv.h (homonym_type_group::get_canonical_type_for): Add a new homonym_type_group_sptr parameter. (homonym_type_group::canonicalize): Likewise. Also, fix the comments and adjust the calls to get_canonical_type_for. * src/abg-ir.cc (add_canonical_type): Update the homonym_type_group::canonical_types_set_ data member. (homonym_type_group::get_canonical_type_for): Add assert. Use add_canonical_type. Fix comment. (canonicalize): Adjust call to homonym_type_group::get_canonical_type_for. Signed-off-by: Dodji Seketeli --- src/abg-ir-priv.h | 25 ++++++++++++------------- src/abg-ir.cc | 18 ++++++++++++++---- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/src/abg-ir-priv.h b/src/abg-ir-priv.h index f04fdfe9..ed453c58 100644 --- a/src/abg-ir-priv.h +++ b/src/abg-ir-priv.h @@ -676,27 +676,26 @@ public: get_canonical_types() const {return canonical_types_;} - /// Get the canonical type for a given canonical type of the current - /// group. - /// - /// @param t the type to consider. - /// - /// @return the canonical type for t. type_base_sptr - get_canonical_type_for(type_base_sptr t); + get_canonical_type_for(type_base_sptr t, homonym_type_group_sptr thiz); - /// @brief Canonicalize all types in this homonym type group. + /// @brief Canonicalize a given type that belongs to the current + /// homonym type group. + /// + /// @param t the type to canonicalize. The type must belong to the + /// current homonym type group. /// - /// Iterate over all types in the homonym type group and compute - /// their canonical type. Types that are structurally equivalent - /// will share the same canonical type. + /// @param this_group a shared pointer to the current @ref + /// homonym_type_group. This is useful because the type will point + /// back to that group. /// /// @param do_log if true, log canonicalization activity to stderr. /// /// @param show_stats if true, show timing statistics for each type /// canonicalization. type_base_sptr - canonicalize(type_base_sptr t, bool do_log, bool show_stats) + canonicalize(type_base_sptr t, homonym_type_group_sptr this_group, + bool do_log, bool show_stats) { if (!t) return t; @@ -717,7 +716,7 @@ public: if (do_log && show_stats) tmr.start(); - type_base_sptr canonical = get_canonical_type_for(t); + type_base_sptr canonical = get_canonical_type_for(t, this_group); if (do_log && show_stats) tmr.stop(); diff --git a/src/abg-ir.cc b/src/abg-ir.cc index a97e77cd..2d300ca1 100644 --- a/src/abg-ir.cc +++ b/src/abg-ir.cc @@ -4019,6 +4019,7 @@ add_canonical_type(type_base_sptr t, homonym_type_group_sptr group) { if (group->canonical_types_set_.find(t) != group->types_set_.end()) return; + group->canonical_types_set_.insert(t); group->canonical_types_.push_back(t); t->priv_->group = group; } @@ -4043,10 +4044,17 @@ add_canonical_type(type_base_sptr t, homonym_type_group_sptr group) /// @param t a smart pointer to instance of @ref type_base we want to /// compute a canonical type for. /// +/// @param this_group this a shared_ptr to the current instance of +/// @ref homonym_type_group. This is used as an argument for +/// homonym_type_group::add_canonical_type. +/// /// @return the canonical type for @p t. type_base_sptr -homonym_type_group::get_canonical_type_for(type_base_sptr t) +homonym_type_group::get_canonical_type_for(type_base_sptr t, + homonym_type_group_sptr this_group) { + ABG_ASSERT(this_group.get() == this); + if (!t) return t; @@ -4221,7 +4229,9 @@ homonym_type_group::get_canonical_type_for(type_base_sptr t) canonical_type_index)) t->priv_->canonical_type_index = canonical_type_index; } - canonical_types_.push_back(result); + + add_canonical_type(result, this_group); + return result; } @@ -16886,7 +16896,7 @@ maybe_adjust_canonical_type(const type_base_sptr& canonical, /// Compute the canonical type of a given type. /// -/// It means that after invoking this function, comparing the intance +/// It means that after invoking this function, comparing the instance /// instance @ref type_base and another one (on which /// type_base::enable_canonical_equality() would have been invoked as /// well) is performed by just comparing the pointer values of the @@ -16931,7 +16941,7 @@ canonicalize(type_base_sptr t, if (do_log && show_stats) tmr.start(); - type_base_sptr canonical = group->get_canonical_type_for(t); + type_base_sptr canonical = group->get_canonical_type_for(t, group); if (do_log && show_stats) tmr.stop();