From patchwork Wed Jun 16 13:30:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Giuliano Procida X-Patchwork-Id: 43857 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 B0507383D83B for ; Wed, 16 Jun 2021 13:30:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B0507383D83B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1623850220; bh=on3vAWUuBc+jaY+NAWULzNS/zEtF8exAv4nYCoQO3Qc=; h=Date:Subject:To:List-Id:List-Unsubscribe:List-Archive:List-Help: List-Subscribe:From:Reply-To:Cc:From; b=ODRrCCZlrr2PXr94xdwBMjBeKZGplY1gfkuZx760+6ntfUAKXifgIhlPqpduL0iu/ MbP3WYcd7UliM7BoHsTGIil28n2Ie11uTq8Qa9zx7Qpj/gtaG2D8j0sK1vYB5lMdef jw3r6JJTLKhmhObduSRgaXtPwGcEIBlAxzpWQEvY= X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from mail-wm1-x349.google.com (mail-wm1-x349.google.com [IPv6:2a00:1450:4864:20::349]) by sourceware.org (Postfix) with ESMTPS id 57AC33850428 for ; Wed, 16 Jun 2021 13:30:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 57AC33850428 Received: by mail-wm1-x349.google.com with SMTP id o32-20020a05600c5120b02901d23584fd92so839021wms.5 for ; Wed, 16 Jun 2021 06:30:16 -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:message-id:mime-version:subject:from:to:cc; bh=on3vAWUuBc+jaY+NAWULzNS/zEtF8exAv4nYCoQO3Qc=; b=TpU8toYJXFtbKt13LvEd+BZabd9gMDRKQ33FtVl2larTHJahuR9UwjP3I3Kv73iHYm 0ECcqxfW82il9VjSpUwhii1hJDq8OyuS/MQlt8DcNMOro1A8odJo85bQ/h+mgudmhuhP dTuLXlwlJa/XvOcOIlKTfL6L/EVswyQj9ggrGc+na6kBABvl00cIuMzLWN6L/tyuZCaE 6XP2UxXSCeSRUuHKhoDsD6ahwm6Hem2fyewa4bXbB4fBHO2dplBpPqC9Twdx13s7a43g qngP0Kp1VKy4QjDdNLVSNe+xFWGZl70RD7sDWEsLpV/de1Q9pXryDprvRL2AGHsA6BIO PpzA== X-Gm-Message-State: AOAM530eKeqgPRdLbKkmgrB1GsndZ+oR5YnlSXjc6320rrXX7tEhWzrx u/sIeqP8KpCGT1LCx3buzr2nhwB9dd0uLvAsFwfJj+UY78AfWe5Sc2M51U/9gLlmf8SR0ezB8Sf A6YjXNC1tQyxOXRur7RoHrJs1I7h0/gRG4AVJaskRNOYi7Qg3PJQK+D2IGZjN1k4zrQzSGCg= X-Google-Smtp-Source: ABdhPJzmX2xV4+uMmtv2Ylb0MxoEciyJE51t+tPB4jHyrPKVHEd2ve3IBW1RWjfeHG8uCBPkDWiMr6Wpz+dWkw== X-Received: from tef.lon.corp.google.com ([2a00:79e0:d:210:9fc5:da3c:780f:b959]) (user=gprocida job=sendgmr) by 2002:a7b:cb0b:: with SMTP id u11mr4047wmj.0.1623850215030; Wed, 16 Jun 2021 06:30:15 -0700 (PDT) Date: Wed, 16 Jun 2021 14:30:03 +0100 Message-Id: <20210616133003.3123930-1-gprocida@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.32.0.272.g935e593368-goog Subject: [PATCH] abg-reader: eliminate unreachable-code-loop-increment warnings To: libabigail@sourceware.org X-Spam-Status: No, score=-22.7 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" This commit tidies up some debris from the change to use xmlFirstElementChild and xmlNextElementSibling. A couple of while loops had bodies which would be executed exactly once searching for the next element with a given tag. These trigger warnings with recent Clang++, at least. This commit replaces the loops with their bodies and eliminates a little redundant conditional logic. There is no change in behaviour. * src/abg-reader.cc (read_translation_unit_from_input): In the branch where the context object holds a non-null node, just check that it an abi-instr; remove the final null check on node as it is guaranteed to be non-null. (read_elf_needed_from_input): Save the context object's node in node immediately; in the branch where the context object holds a non-null node, just check that it an elf-needed; remove the final null check on node as it is guaranteed to be non-null. Signed-off-by: Giuliano Procida Reviewed-by: Matthias Maennich --- src/abg-reader.cc | 41 +++++++++-------------------------------- 1 file changed, 9 insertions(+), 32 deletions(-) diff --git a/src/abg-reader.cc b/src/abg-reader.cc index 0b8149f6..793ca828 100644 --- a/src/abg-reader.cc +++ b/src/abg-reader.cc @@ -1576,21 +1576,10 @@ read_translation_unit_from_input(read_context& ctxt) } else { - node = 0; - for (xmlNodePtr n = ctxt.get_corpus_node(); - n; - n = xmlNextElementSibling(n)) - { - if (!xmlStrEqual(n->name, BAD_CAST("abi-instr"))) - return nil; - node = n; - break; - } + if (!xmlStrEqual(node->name, BAD_CAST("abi-instr"))) + return nil; } - if (node == 0) - return nil; - tu = get_or_read_and_add_translation_unit(ctxt, node); if (ctxt.get_corpus_node()) @@ -1740,9 +1729,8 @@ read_elf_needed_from_input(read_context& ctxt, if (!reader) return false; - xmlNodePtr node = 0; - - if (ctxt.get_corpus_node() == 0) + xmlNodePtr node = ctxt.get_corpus_node(); + if (!node) { int status = 1; while (status == 1 @@ -1762,24 +1750,13 @@ read_elf_needed_from_input(read_context& ctxt, } else { - for (xmlNodePtr n = ctxt.get_corpus_node(); - n; - n = xmlNextElementSibling(n)) - { - if (!xmlStrEqual(n->name, BAD_CAST("elf-needed"))) - return false; - node = n; - break; - } + if (!xmlStrEqual(node->name, BAD_CAST("elf-needed"))) + return false; } - bool result = false; - if (node) - { - result = build_needed(node, needed); - node = xmlNextElementSibling(node); - ctxt.set_corpus_node(node); - } + bool result = build_needed(node, needed); + node = xmlNextElementSibling(node); + ctxt.set_corpus_node(node); return result; }