From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 45894 invoked by alias); 5 Dec 2019 15:26:35 -0000 Mailing-List: contact dwz-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Post: List-Help: List-Subscribe: Sender: dwz-owner@sourceware.org Received: (qmail 45874 invoked by uid 89); 5 Dec 2019 15:26:35 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Checked: by ClamAV 0.100.3 on sourceware.org X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.1 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_PASS autolearn=ham version=3.3.1 spammy= X-Spam-Status: No, score=-25.1 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_PASS autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on sourceware.org X-Spam-Level: X-HELO: mx1.suse.de X-Virus-Scanned: by amavisd-new at test-mx.suse.de Date: Tue, 01 Jan 2019 00:00:00 -0000 From: Tom de Vries To: dwz@sourceware.org, jakub@redhat.com Subject: [committed] Improve --devel-verify-edges Message-ID: <20191205152629.GA26133@delia> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-SW-Source: 2019-q4/txt/msg00114.txt.bz2 Hi, Improvements for verify_edges and verify_edges_1: - improve structure - add comments - add verification of next field Committed to trunk. Thanks, - Tom Improve --devel-verify-edges 2019-12-05 Tom de Vries * dwz.c (verify_edges_1): Add comments. Merge last_idx init and count and last_idx update into fors. (verify_edges): Add comments. Split out verification of initial and new PUs. Verify next field. --- dwz.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 46 insertions(+), 10 deletions(-) diff --git a/dwz.c b/dwz.c index 8eb676c..6f88b82 100644 --- a/dwz.c +++ b/dwz.c @@ -6495,29 +6495,42 @@ static void verify_edges_1 (struct import_cu *ipu, unsigned int *ic, unsigned int *oc) { struct import_edge *e1, *e2; - unsigned int last_idx = 0, count; - for (e1 = ipu->incoming, count = 0; e1; e1 = e1->next) + unsigned int last_idx, count; + + for (last_idx = 0, count = 0, e1 = ipu->incoming; + e1; + last_idx = e1->icu->idx, count++, e1 = e1->next) { + /* Verify that incoming edges are in ascending idx order. */ assert (count == 0 || e1->icu->idx > last_idx); - last_idx = e1->icu->idx; - count++; + + /* Verify that each incoming edge has a corresponding outgoing edge. */ for (e2 = e1->icu->outgoing; e2; e2 = e2->next) if (e2->icu == ipu) break; assert (e2); } + + /* Verify the number of incoming edges. */ assert (ipu->incoming_count == count); - for (e1 = ipu->outgoing, count = 0; e1; e1 = e1->next) + + for (last_idx = 0, count = 0, e1 = ipu->outgoing; + e1; + last_idx = e1->icu->idx, count++, e1 = e1->next) { + /* Verify that outgoing edges are in ascending idx order. */ assert (count == 0 || e1->icu->idx > last_idx); - last_idx = e1->icu->idx; - count++; + + /* Verify that each outgoing edge has a corresponding incoming edge. */ for (e2 = e1->icu->incoming; e2; e2 = e2->next) if (e2->icu == ipu) break; assert (e2); } + + /* Verify the number of outgoing edges. */ assert (ipu->outgoing_count == count); + *ic += ipu->incoming_count; *oc += ipu->outgoing_count; } @@ -6528,11 +6541,34 @@ void verify_edges (struct import_cu **ipus, unsigned int npus, unsigned int ncus) { struct import_cu *ipu; - unsigned int i, ic = 0, oc = 0; - for (ipu = ipus[0]; ipu; ipu = ipu->next) + unsigned int i, ic, oc; + + ic = 0; + oc = 0; + + /* Verify initial PUs. */ + for (i = 0; i < npus; ++i) + { + ipu = ipus[i]; + if (i < npus - 1) + assert (ipu->next == ipus[i + 1]); + verify_edges_1 (ipu, &ic, &oc); + } + + /* Verify new PUs. */ + for (ipu = ipu->next; ipu; ipu = ipu->next) verify_edges_1 (ipu, &ic, &oc); + + /* Verify CUs. */ for (i = 0; i < ncus; i++) - verify_edges_1 (ipus[i + npus], &ic, &oc); + { + ipu = ipus[npus + i]; + assert (ipu->next == NULL); + verify_edges_1 (ipu, &ic, &oc); + } + + /* Verify that the overall number of incoming and outgoing edges is + equal. */ assert (ic == oc); }