From patchwork Tue May 19 10:55:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dodji Seketeli X-Patchwork-Id: 39317 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 06F8D393F846; Tue, 19 May 2020 10:55:44 +0000 (GMT) X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) by sourceware.org (Postfix) with ESMTPS id 7272C393BC3C for ; Tue, 19 May 2020 10:55:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 7272C393BC3C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=seketeli.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=dodji@seketeli.org X-Originating-IP: 91.166.131.130 Received: from localhost (91-166-131-130.subs.proxad.net [91.166.131.130]) (Authenticated sender: dodji@seketeli.org) by relay4-d.mail.gandi.net (Postfix) with ESMTPSA id 1E19CE000B for ; Tue, 19 May 2020 10:55:39 +0000 (UTC) Received: by localhost (Postfix, from userid 1000) id 18CE0581891; Tue, 19 May 2020 12:55:38 +0200 (CEST) From: Dodji Seketeli To: libabigail@sourceware.org Subject: [PATCH] Bug 25989 - type_topo_comp doesn't meet irreflexive requirements Organization: Me, myself and I X-Operating-System: Fedora 33 X-URL: http://www.seketeli.net/~dodji X-Patchwork-State: Committed Date: Tue, 19 May 2020 12:55:38 +0200 Message-ID: <87a7248a8l.fsf@seketeli.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 X-Spam-Status: No, score=-8.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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: 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: , Errors-To: libabigail-bounces@sourceware.org Sender: "Libabigail" Hello, When emitting abixml types inside a given scope are sorted topologically. Types that don't have source definition location information are sorted lexicographically. There are certain types however that need more careful consideration. Those are empty-qualified types. That is, qualified types (like cv-qualified types) that carry no qualifier. The patch explains in-extenso in comments where those types come from. You can also look at the comments of the function maybe_strip_qualification for even more context. Simply put, an empty qualified type like 'NONE reference type' equals it's non-qualified variant 'reference type'. During the topological sorting, we chose to have the empty-qualified variant "come before" (i.e, be "less than") the non-qualified variant. This is alright. The bug however is that we failed to handle the case were we are looking at two empty-qualified types that are equal. In that case, of course, they are meant to be topologically equivalent. Fixed thus. * src/abg-ir.cc (type_topo_comp::operator()): In the comparison operator consider two equivalent empty-qualified types as being topologically equivalent. Signed-off-by: Dodji Seketeli Applied to master. --- src/abg-ir.cc | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/abg-ir.cc b/src/abg-ir.cc index aefbd086..5cc39f59 100644 --- a/src/abg-ir.cc +++ b/src/abg-ir.cc @@ -2740,7 +2740,32 @@ struct type_topo_comp if (s1 == s2) if (qualified_type_def * q = is_qualified_type(f)) if (q->get_cv_quals() == qualified_type_def::CV_NONE) - return true; + if (!is_qualified_type(s)) + // We are looking at two types that are the result of + // an optimization that happens during the IR + // construction. Namely, type f is a cv-qualified + // type with no qualifier (no const, no volatile, no + // nothing, we call it an empty-qualified type). + // These are the result of an optimization which + // removes "redundant qualifiers" from some types. + // For instance, consider a "const reference". The + // const there is redundant because a reference is + // always const. So as a result of the optimizaton + // that type is going to be transformed into an + // empty-qualified reference. If we don't make that + // optimization, then we risk having spurious change + // reports down the road. But then, as a consequence + // of that optimization, we need to sort the + // empty-qualified type and its non-qualified variant + // e.g, to ensure stability in the abixml output; both + // types are logically equal, but here, we decide that + // the empty-qualified one is topologically "less + // than" the non-qualified counterpart. + // + // So here, type f is an empty-qualified type and type + // s is its non-qualified variant. We decide that f + // is topologically less than s. + return true; return (s1 < s2); }