From patchwork Thu Jun 11 13:22:49 2020 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: 39566 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 0DC54389042A; Thu, 11 Jun 2020 13:23:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0DC54389042A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1591881789; bh=6QGY0K1nWlyzGukJAMJhg9PaRyWvl88jS+u0YfPSEPU=; h=Date:In-Reply-To:References:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Help:List-Subscribe:From:Reply-To:Cc:From; b=J3GlUExzyK4q81CPmsytd9XTWFS0+J923YwSK6FF2X/Mx79xnurka4/kF4hDQp+X/ mouN6V29qH+WTJ9OYXczbiLWlB4VTA1I+TIkP4u3KuwA8MkEUK9NkW5jewhcnlL0yb psEI3dnNyY9WsWKZqX3I+hyuhHg02aHUFJ1rbJtc= X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by sourceware.org (Postfix) with ESMTPS id 90845389042A for ; Thu, 11 Jun 2020 13:23:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 90845389042A Received: by mail-yb1-xb49.google.com with SMTP id p22so6512828ybg.21 for ; Thu, 11 Jun 2020 06:23:06 -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=6QGY0K1nWlyzGukJAMJhg9PaRyWvl88jS+u0YfPSEPU=; b=KSHkG2Q623CRfqMzUvStz7p9HozE3oovxXZFtAoipwZbBWz2c+JZtW8Jzu7J4tPbpd 0LRagOS87/mLupCFZh1avXmOrI0KBzMyqipZ/GHIn2KKbiTSI0rcXXyuI2f6VWYEFJKu uU7SJcpdbBt98cFtm9gomvjIVssCuUj8s0X7zR0ub27wrab2PNrPKjv+kLNGHvcSfuSA UBaf9Epu1sRnaUvPDVdQ3qz/pfUHTumaVj3w7HTCCyXxdywaQQpsTqmDq4vzTrNjmRaN nUlOpp3hy8sag3csUHTHnjdH8mDleeakV9aSA0cXQVEIiLN3QQfB5mxkofCCSkp7NnjA TcmA== X-Gm-Message-State: AOAM530eIzv1QBIwKdEJ65dOohtBDNIjEwS/6GkdNWmksbUz6Mwbh1qF Q7yEIIrMzew1r7ixfMzczQek1rYHdf2zXPpDIBuOtbNM8OKOD/3+nWXheG83fT4w0ArdoQzN04D scxed+lntOV5hFmaqpB4bIPnb2i5yHQrythnlc0y/SNpRs5y0R+SGzf/8bOIzcqAuKiNIqvw= X-Google-Smtp-Source: ABdhPJxoha+dsEQU7ZHkQu3fCtlwhKsj0USozyswh95tvlv/MWvTygW7UPKw+m2ipcNfrY17oe5u0mfQNwtaEA== X-Received: by 2002:a25:2041:: with SMTP id g62mr13949697ybg.429.1591881785891; Thu, 11 Jun 2020 06:23:05 -0700 (PDT) Date: Thu, 11 Jun 2020 15:22:49 +0200 In-Reply-To: <20200604103237.53270-1-maennich@google.com> Message-Id: <20200611132249.109405-1-maennich@google.com> Mime-Version: 1.0 References: <20200604103237.53270-1-maennich@google.com> X-Mailer: git-send-email 2.27.0.278.ge193c7cf3a9-goog Subject: [PATCH v2] dwarf-reader: get_die_source: always initialize return value To: libabigail@sourceware.org X-Spam-Status: No, score=-24.0 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: Matthias Maennich via Libabigail From: =?utf-8?q?Matthias_M=C3=A4nnich?= Reply-To: Matthias Maennich Cc: maennich@google.com, gprocida@google.com, kernel-team@android.com Errors-To: libabigail-bounces@sourceware.org Sender: "Libabigail" GCC9 with ABIGAIL_DEVEL=1 and ABIGAIL_DEBUG=1 set, regularly emits -Werror=maybe-uninitialized for the values gathered by get_die_source. As a counter measure, some of them were initialized before the call to NO_DEBUG_INFO_DIE_SOURCE, but not all of them, leading to said warning. In order to overcome this, let get_die_source always initialize the source to NO_DEBUG_INFO_DIE_SOURCE and adjust the caller to consistently not do that anymore. This solves the warning and maybe but unlikely (due to the ABG_ASSERT) avoids some UB. Changing the interface of get_die_source to return the source directly, lead to the ability to initialize the value const and to defer the assertion to the function itself. Some occurrences could be removed entirely as the die_source was not used at all. * src/abg-dwarf-reader.cc (read_context::get_die_source): Always initialize die_source. (read_context::ContainerType::get_container): Fix initialization of die_source. (read_context::compute_canonical_die): Likewise. (read_context::get_canonical_die): Likewise. (read_context::get_or_compute_canonical_die): Likewise. (read_context::associate_die_to_decl): Likewise. (read_context::set_canonical_die_offset): Likewise. (read_context::schedule_type_for_late_canonicalization): Likewise. (read_context::compare_dies): Likewise. (read_context::get_parent_die): Likewise. (read_context::get_scope_for_die): Likewise. (read_context::add_or_update_union_type): Likewise. (read_context::maybe_canonicalize_type): Likewise. (read_context::build_ir_node_from_die): Likewise. Signed-off-by: Matthias Maennich --- src/abg-dwarf-reader.cc | 98 +++++++++++------------------------------ 1 file changed, 26 insertions(+), 72 deletions(-) diff --git a/src/abg-dwarf-reader.cc b/src/abg-dwarf-reader.cc index 05130730d5ec..213638102230 100644 --- a/src/abg-dwarf-reader.cc +++ b/src/abg-dwarf-reader.cc @@ -2106,8 +2106,7 @@ public: ContainerType& get_container(const read_context& ctxt, const Dwarf_Die *die) { - die_source source = NO_DEBUG_INFO_DIE_SOURCE; - ABG_ASSERT(ctxt.get_die_source(die, source)); + const die_source source = ctxt.get_die_source(die); return get_container(source); } @@ -2891,9 +2890,7 @@ public: Dwarf_Die &canonical_die, bool die_as_type) const { - die_source source = NO_DEBUG_INFO_DIE_SOURCE; - - ABG_ASSERT(get_die_source(die, source)); + const die_source source = get_die_source(die); Dwarf_Off die_offset = dwarf_dieoffset(const_cast(die)); @@ -3021,8 +3018,7 @@ public: size_t where, bool die_as_type) const { - die_source source; - ABG_ASSERT(get_die_source(die, source)); + const die_source source = get_die_source(die); offset_offset_map_type &canonical_dies = die_as_type @@ -3130,8 +3126,7 @@ public: size_t where, bool die_as_type) const { - die_source source = NO_DEBUG_INFO_DIE_SOURCE; - ABG_ASSERT(get_die_source(die, source)); + const die_source source = get_die_source(die); offset_offset_map_type &canonical_dies = die_as_type @@ -3240,16 +3235,15 @@ public: /// /// @param die the DIE to get the source of. /// - /// @param source out parameter. The function sets this parameter - /// to the source of the DIE @p iff it returns true. - /// - /// @return true iff the source of the DIE could be determined and - /// returned. - bool - get_die_source(const Dwarf_Die *die, die_source &source) const + /// @return the source of the DIE if it could be determined, + /// NO_DEBUG_INFO_DIE_SOURCE otherwise. + die_source + get_die_source(const Dwarf_Die *die) const { + die_source source = NO_DEBUG_INFO_DIE_SOURCE; ABG_ASSERT(die); - return get_die_source(*die, source); + ABG_ASSERT(get_die_source(*die, source)); + return source; } /// Get the source of the DIE. @@ -3353,8 +3347,7 @@ public: size_t where_offset, bool do_associate_by_repr = false) { - die_source source = NO_DEBUG_INFO_DIE_SOURCE; - ABG_ASSERT(get_die_source(die, source)); + const die_source source = get_die_source(die); die_artefact_map_type& m = decl_die_artefact_maps().get_container(source); @@ -3981,8 +3974,7 @@ public: Dwarf_Off canonical_die_offset, bool die_as_type) const { - die_source source = NO_DEBUG_INFO_DIE_SOURCE; - ABG_ASSERT(get_die_source(die, source)); + const die_source source = get_die_source(die); Dwarf_Off die_offset = dwarf_dieoffset(const_cast(die)); @@ -4562,14 +4554,13 @@ public: schedule_type_for_late_canonicalization(const Dwarf_Die *die) { Dwarf_Off o; - die_source source = NO_DEBUG_INFO_DIE_SOURCE; Dwarf_Die equiv_die; ABG_ASSERT(get_canonical_die(die, equiv_die, /*where=*/0, /*die_as_type=*/true)); - ABG_ASSERT(get_die_source(&equiv_die, source)); + const die_source source = get_die_source(&equiv_die); o = dwarf_dieoffset(&equiv_die); const die_artefact_map_type& m = @@ -11397,10 +11388,8 @@ compare_dies(const read_context& ctxt, Dwarf_Off l_offset = dwarf_dieoffset(const_cast(l)), r_offset = dwarf_dieoffset(const_cast(r)); Dwarf_Off l_canonical_die_offset = 0, r_canonical_die_offset = 0; - die_source l_die_source = NO_DEBUG_INFO_DIE_SOURCE, - r_die_source = NO_DEBUG_INFO_DIE_SOURCE; - ABG_ASSERT(ctxt.get_die_source(l, l_die_source)); - ABG_ASSERT(ctxt.get_die_source(r, r_die_source)); + const die_source l_die_source = ctxt.get_die_source(l); + const die_source r_die_source = ctxt.get_die_source(r); // If 'l' and 'r' already have canonical DIEs, then just compare the // offsets of their canonical DIEs. @@ -11847,10 +11836,9 @@ compare_dies(const read_context& ctxt, // // In case 'r' has no canonical DIE, then compute it, and then // propagate that canonical DIE to 'r'. - die_source l_source = NO_DEBUG_INFO_DIE_SOURCE, - r_source = NO_DEBUG_INFO_DIE_SOURCE; - ABG_ASSERT(ctxt.get_die_source(l, l_source)); - ABG_ASSERT(ctxt.get_die_source(r, r_source)); + const die_source l_source = ctxt.get_die_source(l); + const die_source r_source = ctxt.get_die_source(r); + if (!l_has_canonical_die_offset // A DIE can be equivalent only to another DIE of the same // source. @@ -12102,8 +12090,7 @@ get_parent_die(const read_context& ctxt, { ABG_ASSERT(ctxt.dwarf()); - die_source source = NO_DEBUG_INFO_DIE_SOURCE; - ABG_ASSERT(ctxt.get_die_source(die, source)); + const die_source source = ctxt.get_die_source(die); const offset_offset_map_type& m = ctxt.die_parent_map(source); offset_offset_map_type::const_iterator i = @@ -12238,8 +12225,7 @@ get_scope_for_die(read_context& ctxt, bool called_for_public_decl, size_t where_offset) { - die_source source_of_die = NO_DEBUG_INFO_DIE_SOURCE; - ABG_ASSERT(ctxt.get_die_source(die, source_of_die)); + const die_source source_of_die = ctxt.get_die_source(die); if (is_c_language(ctxt.cur_transl_unit()->get_language())) { @@ -12695,9 +12681,6 @@ build_namespace_decl_and_add_to_ir(read_context& ctxt, if (!die) return result; - die_source source; - ABG_ASSERT(ctxt.get_die_source(die, source)); - unsigned tag = dwarf_tag(die); if (tag != DW_TAG_namespace && tag != DW_TAG_module) return result; @@ -13308,8 +13291,7 @@ add_or_update_class_type(read_context& ctxt, if (!die) return result; - die_source source; - ABG_ASSERT(ctxt.get_die_source(die, source)); + const die_source source = ctxt.get_die_source(die); unsigned tag = dwarf_tag(die); @@ -13686,8 +13668,7 @@ add_or_update_union_type(read_context& ctxt, if (tag != DW_TAG_union_type) return result; - die_source source = NO_DEBUG_INFO_DIE_SOURCE; - ABG_ASSERT(ctxt.get_die_source(die, source)); + const die_source source = ctxt.get_die_source(die); { die_class_or_union_map_type::const_iterator i = ctxt.die_wip_classes_map(source).find(dwarf_dieoffset(die)); @@ -13912,9 +13893,6 @@ build_qualified_type(read_context& ctxt, if (!die) return result; - die_source source; - ABG_ASSERT(ctxt.get_die_source(die, source)); - unsigned tag = dwarf_tag(die); if (tag != DW_TAG_const_type @@ -14090,9 +14068,6 @@ build_pointer_type_def(read_context& ctxt, if (!die) return result; - die_source source; - ABG_ASSERT(ctxt.get_die_source(die, source)); - unsigned tag = dwarf_tag(die); if (tag != DW_TAG_pointer_type) return result; @@ -14174,9 +14149,6 @@ build_reference_type(read_context& ctxt, if (!die) return result; - die_source source; - ABG_ASSERT(ctxt.get_die_source(die, source)); - unsigned tag = dwarf_tag(die); if (tag != DW_TAG_reference_type && tag != DW_TAG_rvalue_reference_type) @@ -14258,8 +14230,7 @@ build_function_type(read_context& ctxt, ABG_ASSERT(dwarf_tag(die) == DW_TAG_subroutine_type || dwarf_tag(die) == DW_TAG_subprogram); - die_source source; - ABG_ASSERT(ctxt.get_die_source(die, source)); + const die_source source = ctxt.get_die_source(die); decl_base_sptr type_decl; @@ -14462,9 +14433,6 @@ build_subrange_type(read_context& ctxt, if (!die) return result; - die_source source; - ABG_ASSERT(ctxt.get_die_source(die, source)); - unsigned tag = dwarf_tag(const_cast(die)); if (tag != DW_TAG_subrange_type) return result; @@ -14639,9 +14607,6 @@ build_array_type(read_context& ctxt, if (!die) return result; - die_source source; - ABG_ASSERT(ctxt.get_die_source(die, source)); - unsigned tag = dwarf_tag(die); if (tag != DW_TAG_array_type) return result; @@ -14704,9 +14669,6 @@ build_typedef_type(read_context& ctxt, if (!die) return result; - die_source source; - ABG_ASSERT(ctxt.get_die_source(die, source)); - unsigned tag = dwarf_tag(die); if (tag != DW_TAG_typedef) return result; @@ -14875,9 +14837,6 @@ build_var_decl(read_context& ctxt, if (!die_is_public_decl(die)) return result; - die_source source; - ABG_ASSERT(ctxt.get_die_source(die, source)); - type_base_sptr type; Dwarf_Die type_die; if (die_die_attribute(die, DW_AT_type, type_die)) @@ -15311,9 +15270,6 @@ build_function_decl(read_context& ctxt, return result; ABG_ASSERT(dwarf_tag(die) == DW_TAG_subprogram); - die_source source; - ABG_ASSERT(ctxt.get_die_source(die, source)); - if (!die_is_public_decl(die)) return result; @@ -15777,8 +15733,7 @@ read_debug_info_into_corpus(read_context& ctxt) static void maybe_canonicalize_type(const Dwarf_Die *die, read_context& ctxt) { - die_source source = NO_DEBUG_INFO_DIE_SOURCE; - ABG_ASSERT(ctxt.get_die_source(die, source)); + const die_source source = ctxt.get_die_source(die); size_t die_offset = dwarf_dieoffset(const_cast(die)); type_base_sptr t = ctxt.lookup_type_from_die(die); @@ -15990,8 +15945,7 @@ build_ir_node_from_die(read_context& ctxt, return result; } - die_source source_of_die = NO_DEBUG_INFO_DIE_SOURCE; - ABG_ASSERT(ctxt.get_die_source(die, source_of_die)); + const die_source source_of_die = ctxt.get_die_source(die); if ((result = ctxt.lookup_decl_from_die_offset(dwarf_dieoffset(die), source_of_die)))