From patchwork Fri Jan 26 10:28:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dodji Seketeli X-Patchwork-Id: 84785 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 D03DD3858CD1 for ; Fri, 26 Jan 2024 10:28:48 +0000 (GMT) X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id BAA9B3858C2D for ; Fri, 26 Jan 2024 10:28:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BAA9B3858C2D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org BAA9B3858C2D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706264923; cv=none; b=sd7bSTzYRO0O+ADayCGv48yIhqsXK2hMS6MtFXnd15AgRIXoFut/3pVE/4B149f5qs/BeE113RkC7ORyVMfool8O2/1+8/dYST+x8w51MfSp/VHRPG1kzQWvb82/49+mNw8Imp9kr40Ne0V1f0jpEyxt+GnOfRt59HddPgJZIcU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706264923; c=relaxed/simple; bh=kvhbe3y9yB0rkZFuPrzY7EbiTCLfreqLygtxFybIjf0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=anaaAsMxFv8O1Gd20lyLqFdJgJL2oMm7/dybiYjyt2jO1Am5FucUo+PD6IeNFYMBCaRDVzMYQfrsttuXkSd6BT6vrbqCTG2KiCVNFeGy0m9DOwpk0N5mcageHjEbTYOkxN8CmcUtYEda+3CC2nKRLNR1KPQhgCo3iSrLmC11kvw= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706264921; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=Am2PnpwmxYJkHtt3JMLTf8igUJP9ZQeyRQB0SMLZleo=; b=BexDU9w9fKWiwnQp7Fn3GjQRHoYHD1xoDpRZqEPwN/POL/ZHtm51/+diRmtDVHZx+XL6F1 UlK4r/RrLYXTTeA4HGVIoyexsfYy5Mi+E+LGF5tIAEbKRd+ALyHLI5GzXRECj8JL/mTbO6 /nh1hQEazj4WRiNBI28BUDteZZYfS8k= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-249-Dy1ROloXNUGvdegD97bBOg-1; Fri, 26 Jan 2024 05:28:39 -0500 X-MC-Unique: Dy1ROloXNUGvdegD97bBOg-1 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-7833761135dso88593185a.0 for ; Fri, 26 Jan 2024 02:28:39 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706264919; x=1706869719; h=mime-version:user-agent:message-id:date:organization:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Am2PnpwmxYJkHtt3JMLTf8igUJP9ZQeyRQB0SMLZleo=; b=Gv6X212J9oYxqmZqxek8NEwVz7AozCJSH5m/KTmD4YZbDNsOG+1jAnTt4FmSILE4zD /qpz/1fJiOJcTwyeLs0TZhdazYENAjihuORQ+qZJIofbhInGLrKWoNncYrrmTgMvX2Wv Aoxp4Il96PhJ+cE5Lv8YB/IOC6ZwKftpjT7A90Q8x0u36b375l8agdyd0rs/vB7SUloE kSz0Tz0WnKmv8it0C8S7tmhmWFf9HgTgs39uw53/0pJkx8An9NS2xN3OMmhElGepXW70 HfJaDA5Qq2ZCklAalFSmkT3DuPSWWN5mjlV1LsiVzn2OSqgeihLdawPtHHMsZVSy/cwE Opeg== X-Gm-Message-State: AOJu0Yxr+vUaL8+T1OxoqrFbhfPZrqmPHpfR5oXHa2mStU64EUszS4pL R26ELgTFjCib0ZGGeblgOXzmeQA65pUQYugg2z/Rw1ordSBrET1NCwf96R7AdTDc9nZ4ZbB5UAL 2UsXOJxVlJDkOZSBBFBlCc4IMZoUfAJ+on+P7GjxJ8bhmwk0BlVn9yuYh71MxFfhYTIXJlHgE72 gjF+KEbCl7GXxBY8h4Q5Qb9lGSPlv2TkJs2JP+nw== X-Received: by 2002:a05:620a:c1b:b0:783:8e62:4e10 with SMTP id l27-20020a05620a0c1b00b007838e624e10mr1102787qki.34.1706264919047; Fri, 26 Jan 2024 02:28:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IEkkhUvU4lzDAsAfXJ7wrVMGFHotsJCIFJwlVf+cbi0ugqUJ4yOpyRBaucx9PXZnkCtZ4EvRw== X-Received: by 2002:a05:620a:c1b:b0:783:8e62:4e10 with SMTP id l27-20020a05620a0c1b00b007838e624e10mr1102777qki.34.1706264918575; Fri, 26 Jan 2024 02:28:38 -0800 (PST) Received: from localhost (88-120-130-27.subs.proxad.net. [88.120.130.27]) by smtp.gmail.com with ESMTPSA id t9-20020a05620a0b0900b00783268da8f0sm451634qkg.40.2024.01.26.02.28.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jan 2024 02:28:38 -0800 (PST) Received: by localhost (Postfix, from userid 1000) id 84A5C5077C6B; Fri, 26 Jan 2024 11:28:35 +0100 (CET) From: Dodji Seketeli To: libabigail@sourceware.org Subject: [PATCH, applied] Bug 31279 - Acknowledge that opaque types are always decl-only Organization: Red Hat / France X-Operating-System: AlmaLinux 9.3 X-URL: http://www.redhat.com Date: Fri, 26 Jan 2024 11:28:35 +0100 Message-ID: <87plxo1j8s.fsf@redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.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 Hello, When handling a decl-only base class, add_or_update_class_type asserts that we need to try to resolve the decl-only base class to its definition. That makes sense in most cases. However, in cases where the base class is actually an opaque class resulting from the use of the --header-dir{1,2} option of abidiff, the opaque type is by definition a decl-only class artificially created from a fully defined class. When the opaque class is anonymous (later named by a typedef), maybe_schedule_declaration_only_class_for_resolution schedules a decl-only class named by the empty string for resolution to its definition. Later when add_or_update_class_type handles the decl-only base class (now named by a typedef), reader::is_decl_only_class_scheduled_for_resolution looks for the typedef name; as the class scheduled for resolution by maybe_schedule_declaration_only_class_for_resolution was then anonymous, reader::is_decl_only_class_scheduled_for_resolution returns false and the assert in add_or_update_class_type fails. It's the problem reported in this issue. Oops. When the opaqued decl-only type is anonymous, maybe_schedule_declaration_only_{class,enum}_for_resolution must NOT schedule it for resolution to its definition because the scheduled types for resolution are designated by name. This patch now enforces that. It just doesn't make sense to schedule an anonymous type for resolution to its definition. When the type is later named by a typedef however, then it's scheduled for resolution to its definition, as it's no more anonymous at that point. The patch enforces that as well. The patch ends up making sure that add_or_update_class_type does /not/ assert that an /anonymous/ decl-only base class is scheduled for resolution to its definition. These changes should fix the problem reported at https://sourceware.org/bugzilla/show_bug.cgi?id=31279. * src/abg-dwarf-reader.cc (reader::maybe_schedule_declaration_only_{class,enum}_for_resolution): Do not schedule anonymous decl-only types for resolution to their definition. (build_typedef_type): When an anonymous decl-only type has just been named by a typedef, schedule it for resolution to its definition. (add_or_update_class_type): Do not assert that /anonymous/ decl-only types are scheduled for resolution to their definition. Signed-off-by: Dodji Seketeli Applied to master. --- src/abg-dwarf-reader.cc | 43 ++++++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/src/abg-dwarf-reader.cc b/src/abg-dwarf-reader.cc index 70e37403..735f0342 100644 --- a/src/abg-dwarf-reader.cc +++ b/src/abg-dwarf-reader.cc @@ -3990,7 +3990,12 @@ public: maybe_schedule_declaration_only_class_for_resolution(const class_or_union_sptr& cou) { if (cou->get_is_declaration_only() - && cou->get_definition_of_declaration() == 0) + && cou->get_definition_of_declaration() == 0 + // Make sure the class is not anonymous. Anonymous classes + // are usually later named by a typedef. At that time, after + // being named by a typedef, this method is going to be called + // with the class being named by the typedef. + && !cou->get_qualified_name().empty()) { string qn = cou->get_qualified_name(); string_classes_or_unions_map::iterator record = @@ -4013,8 +4018,10 @@ public: is_decl_only_class_scheduled_for_resolution(const class_or_union_sptr& cou) { if (cou->get_is_declaration_only()) - return (declaration_only_classes().find(cou->get_qualified_name()) - != declaration_only_classes().end()); + return ((declaration_only_classes().find(cou->get_qualified_name()) + != declaration_only_classes().end()) + || (declaration_only_classes().find(cou->get_name()) + != declaration_only_classes().end())); return false; } @@ -4250,10 +4257,15 @@ public: /// /// @param enom the enum to consider. void - maybe_schedule_declaration_only_enum_for_resolution(enum_type_decl_sptr& enom) + maybe_schedule_declaration_only_enum_for_resolution(const enum_type_decl_sptr& enom) { if (enom->get_is_declaration_only() - && enom->get_definition_of_declaration() == 0) + && enom->get_definition_of_declaration() == 0 + // Make sure the enum is not anonymous. Anonymous enums are + // usually later named by a typedef. At that time, after + // being named by a typedef, this method is going to be called + // with the enum being named by the typedef. + && !enom->get_qualified_name().empty()) { string qn = enom->get_qualified_name(); string_enums_map::iterator record = @@ -13209,7 +13221,14 @@ add_or_update_class_type(reader& rdr, (b, access, is_offset_present ? offset : -1, is_virt)); - if (b->get_is_declaration_only()) + if (b->get_is_declaration_only() + // Only non-anonymous decl-only classes are + // scheduled for resolution to their definition. + // Anonymous classes that are decl-only are likely + // only artificially created by + // get_opaque_version_of_type, from anonymous fully + // defined classes. Those are never defined. + && !b->get_qualified_name().empty()) ABG_ASSERT(rdr.is_decl_only_class_scheduled_for_resolution(b)); if (result->find_base_class(b->get_qualified_name())) continue; @@ -14617,6 +14636,12 @@ build_typedef_type(reader& rdr, decl_base_sptr decl = is_decl(utype); ABG_ASSERT(decl); decl->set_naming_typedef(result); + if (is_class_or_union_type(utype)) + rdr.maybe_schedule_declaration_only_class_for_resolution + (is_class_or_union_type(utype)); + else if (is_enum_type(utype)) + rdr.maybe_schedule_declaration_only_enum_for_resolution + (is_enum_type(utype)); } } @@ -15107,9 +15132,9 @@ type_is_suppressed(const reader& rdr, /// nil if no opaque version was found. static type_or_decl_base_sptr get_opaque_version_of_type(reader &rdr, - scope_decl *scope, - Dwarf_Die *type_die, - size_t where_offset) + scope_decl *scope, + Dwarf_Die *type_die, + size_t where_offset) { type_or_decl_base_sptr result;