From patchwork Fri Jun 11 17:04:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Giuliano Procida X-Patchwork-Id: 43840 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 916EE3AAB4B1 for ; Fri, 11 Jun 2021 17:07:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 916EE3AAB4B1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1623431238; bh=ozLmt6pqzbbDBsE5boGCMtG3JkIyH76+lyi8J2sWNSE=; h=Date:In-Reply-To:References:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Help:List-Subscribe:From:Reply-To:Cc:From; b=NX0IAC/GMmW/LKTeLCbNs/9jwh8ip6pwpMviaO61LXEcQOzz4v+L08wFLZOeutu8A N3Dgn9n4sT721xveJijV6dSK4ZO8j3VPB4erbt+0jNtKrrfhWe9LXtoX7HXxSeCPUT hYB28sVN9vvbrCSbEiYT0QokJQbfcmQseyqXAuEo= X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from mail-wm1-x34a.google.com (mail-wm1-x34a.google.com [IPv6:2a00:1450:4864:20::34a]) by sourceware.org (Postfix) with ESMTPS id ECA653B8A422 for ; Fri, 11 Jun 2021 17:04:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org ECA653B8A422 Received: by mail-wm1-x34a.google.com with SMTP id n8-20020a05600c3b88b02901b6e5bcd841so1850907wms.9 for ; Fri, 11 Jun 2021 10:04:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=ozLmt6pqzbbDBsE5boGCMtG3JkIyH76+lyi8J2sWNSE=; b=RZU+KqC4xbXVuN2sVFJJwiCaiTR0DCSV5ujydrR/LVMyJ4uXcxDRzmvN9nU1WQlj1z ixRdLqwJ4qac7SpKPJIgYNldUm3x2Ol4v5/4lDwtH8C925mXHxucjTcjX9GkAleWekKr EflrIEO0H8jZytP+IgTQK4MTf8NoNr5KCwRuegXi6qV0PZusqukUf3VvFZA2kKPXZYSo ccLwiuSKoCqpjdB1ROGe8BRiZbfMKGx4Eg9VEdnSYG51SMU/b+zWE1GnNSDfrlVcAoux h7uiX8LwMt2ZdV5l9mfw4jP7kicQYmqB1Z0E2CBJ/tYmdS45X0l9dF5KN6nNbuYfjyRR 7HIg== X-Gm-Message-State: AOAM531H3GYBP1BHSuvxkOO1RyT59RQQJKJDuh5lwbafidWOnAUpkUwp mOFMaU4oVK7xXPFS5Z30n3GulfRqjksALrkcRs5UkS4F5l5xDD/dQZfofULgrtTNybzVNsSBVCl 0/hLu085PQuuaT480/w23WG3yT10h45oCEAGXDcLKO7c6zj59BB45gRqqsoP/fViT6bUS+TY= X-Google-Smtp-Source: ABdhPJyefU1OkNttap07BvVtom3+Nij9DaqKt/eDb9P8fcaxgu9PUiqE8705uIph1D8HygnOSzB5EZJVNt89oQ== X-Received: from tef.lon.corp.google.com ([2a00:79e0:d:210:c264:c1f9:cf3c:2c0b]) (user=gprocida job=sendgmr) by 2002:a5d:60c8:: with SMTP id x8mr5369358wrt.382.1623431091413; Fri, 11 Jun 2021 10:04:51 -0700 (PDT) Date: Fri, 11 Jun 2021 18:04:42 +0100 In-Reply-To: <20210611170442.845802-1-gprocida@google.com> Message-Id: <20210611170442.845802-3-gprocida@google.com> Mime-Version: 1.0 References: <20210611170442.845802-1-gprocida@google.com> X-Mailer: git-send-email 2.32.0.272.g935e593368-goog Subject: [PATCH 2/2] XML writer: emit enclosing types of scoped declarations To: libabigail@sourceware.org X-Spam-Status: No, score=-23.1 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.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Giuliano Procida via Libabigail From: Giuliano Procida Reply-To: Giuliano Procida Cc: maennich@google.com, kernel-team@android.com Errors-To: libabigail-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libabigail" Bug 26591 - detect pathologically redundant types in abixml One source of duplicated type ids in ABI XML was the writer emitting scoped (nested) typed declarations before a later TU causes the emission of the complete enclosing type declaration. This no longer seems to occur within the current test suite. The code paths responsible are still active though, but don't ever appear to be asked to emit nested member types. This commit was my fix for the issue. It causes the outermost enclosing type declaration to be emitted immediately, rather than a nested member type. This prevents the later duplicate emission of the enclosing type and all its nested member types. This commit still does simplify the code paths and avoids the potential emission of partial types (which were sometimes accompanied by incorrect member-type access attributes). * src/abg-writer.cc: (write_decl_in_scope): Emit the enclosing types of any nested type declaration. Signed-off-by: Giuliano Procida --- src/abg-writer.cc | 35 ++++++++++++----------------------- 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/src/abg-writer.cc b/src/abg-writer.cc index 8aa95948..cf2693bf 100644 --- a/src/abg-writer.cc +++ b/src/abg-writer.cc @@ -1941,6 +1941,8 @@ write_decl(const decl_base_sptr& decl, write_context& ctxt, unsigned indent) /// Emit a declaration, along with its scope. /// +/// If the scope includes another type declaration, emit that instead. +/// /// This function is called at the end of emitting a translation unit, /// to emit type declarations that were referenced by types that were /// emitted in the TU already, but that were not emitted themselves. @@ -1972,6 +1974,7 @@ write_decl_in_scope(const decl_base_sptr& decl, stack closing_tags; stack closing_indents; unsigned indent = initial_indent; + bool done = false; for (list::const_iterator i = scopes.begin(); i != scopes.end(); ++i) @@ -1987,43 +1990,29 @@ write_decl_in_scope(const decl_base_sptr& decl, << "'>\n"; closing_tags.push(""); closing_indents.push(indent); + indent += c.get_xml_element_indent(); } - // ... or a class. + // ... or a class ... else if (class_decl* c = is_class_type(*i)) { class_decl_sptr class_type(c, noop_deleter()); - write_class_decl_opening_tag(class_type, "", ctxt, indent, - /*prepare_to_handle_members=*/false); - closing_tags.push(""); - closing_indents.push(indent); - - unsigned nb_ws = get_indent_to_level(ctxt, indent, 1); - write_member_type_opening_tag(type, ctxt, nb_ws); - indent = nb_ws; - closing_tags.push(""); - closing_indents.push(nb_ws); + write_class_decl(class_type, ctxt, indent); + done = true; } + // ... or a union. else if (union_decl *u = is_union_type(*i)) { union_decl_sptr union_type(u, noop_deleter()); - write_union_decl_opening_tag(union_type, "", ctxt, indent, - /*prepare_to_handle_members=*/false); - closing_tags.push(""); - closing_indents.push(indent); - - unsigned nb_ws = get_indent_to_level(ctxt, indent, 1); - write_member_type_opening_tag(type, ctxt, nb_ws); - indent = nb_ws; - closing_tags.push(""); - closing_indents.push(nb_ws); + write_union_decl(union_type, ctxt, indent); + done = true; } else // We should never reach this point. abort(); - indent += c.get_xml_element_indent(); } - write_decl(decl, ctxt, indent); + if (!done) + write_decl(decl, ctxt, indent); while (!closing_tags.empty()) {