From patchwork Fri Aug 4 20:09:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 9881983 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id ED742602B8 for ; Fri, 4 Aug 2017 20:09:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DEC6F2890A for ; Fri, 4 Aug 2017 20:09:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D3B3A28918; Fri, 4 Aug 2017 20:09:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D0ADF289DA for ; Fri, 4 Aug 2017 20:09:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751977AbdHDUJ3 (ORCPT ); Fri, 4 Aug 2017 16:09:29 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:37229 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752050AbdHDUJ2 (ORCPT ); Fri, 4 Aug 2017 16:09:28 -0400 Received: by mail-wm0-f65.google.com with SMTP id t138so6802863wmt.4 for ; Fri, 04 Aug 2017 13:09:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=kwCqK1InDBfhOiUngn9VMprPV+CYjqau93nhgZebFCA=; b=jFFH2nMaKcs5Ag2cGu9Ybe5ugZMvVzPSio4FY8eYy6iRQq/9nizAGKA8L1grxiXBwv +eDYYRSPKqK6nl+qC5A00Cp9kqWj1SYQO+dqxA+pUS3nLDpVhML902ltk6i95k9645jU w3VlyCmJFnQDOGKIA1n6sSo6aGFN7hc+I8am4jSqWflM9+ICFzNfVuU6FXuoE5MFLeNW gUd672ITtx8Gb9zXL7LMDGB2sHymIafBjXg0knxXwvNvLue+Vt1zf0YC/ZXYMw73+Kld GlsguTN+Y73Iox4zpJpj0KovnoI5UcBM1KJMVrpqxnI7zaPWKSqZKk6okVPRQJAB7Hum 1ZPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=kwCqK1InDBfhOiUngn9VMprPV+CYjqau93nhgZebFCA=; b=WQ0TGlTUyTPD0fqHbPCPu4DVhqOYdo9CNOa88bumTLUYISZ6MjZkSSdQlB4Z//svF+ 6Yrm+39rqmSfw0SSvM+glHGJQhbJkFxWPqfgvEBbIMZSjPPUrCnVNi2i6mA6hz2DXcy7 t4lMkAgZipC4oQ9rRV+VqgHmKsue1ck5KJRc7KXk1D1hpuVS8TCou1ouLeKv0WQCIdv9 ferjaAEIoyHf5VCiiqD2cqQbILXwTCwxECgBdNqw15QvTbYxNTyk0ERsOj7pK0ExQPMa Ft7ZUr1S2g/BUB2J4Kiwt/YJNftcUBCyhNVH6Otjrf8rl99WcZ9ARO3SbCs/+VhXakCI Ok/g== X-Gm-Message-State: AHYfb5jOEUBozRfchWvxnbrwDo6UsDap7+suyTPuB/pRwZZKaT4AJy9g NjzpNl/k7hmgWQ== X-Received: by 10.28.220.85 with SMTP id t82mr1954671wmg.10.1501877367470; Fri, 04 Aug 2017 13:09:27 -0700 (PDT) Received: from localhost.localdomain ([109.129.207.142]) by smtp.gmail.com with ESMTPSA id q27sm4652682wrc.94.2017.08.04.13.09.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 04 Aug 2017 13:09:26 -0700 (PDT) From: Luc Van Oostenryck To: Christopher Li Cc: linux-sparse@vger.kernel.org, Luc Van Oostenryck Subject: [PATCH 4/4] mark pseudo users as deleted instead of removing them Date: Fri, 4 Aug 2017 22:09:15 +0200 Message-Id: <20170804200915.56738-5-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.13.2 In-Reply-To: <20170804200915.56738-1-luc.vanoostenryck@gmail.com> References: <20170804200915.56738-1-luc.vanoostenryck@gmail.com> Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This will fix the (rare) problems with deletion while doing nested ptrlist walking that occurs when doing recursive kill_instruction() - remove_usage() - kill_instruction() Signed-off-by: Luc Van Oostenryck --- flow.c | 28 ++++++++++++++++++++++------ linearize.c | 2 ++ memops.c | 5 ++++- simplify.c | 10 ++++++++-- unssa.c | 2 ++ 5 files changed, 38 insertions(+), 9 deletions(-) diff --git a/flow.c b/flow.c index 6cac21b24..1dbfd431e 100644 --- a/flow.c +++ b/flow.c @@ -283,6 +283,8 @@ void convert_instruction_target(struct instruction *insn, pseudo_t src) if (target == src) return; FOR_EACH_PTR(target->users, pu) { + if (!pu) + continue; if (*pu->userp != VOID) { assert(*pu->userp == target); *pu->userp = src; @@ -675,8 +677,10 @@ static void simplify_one_symbol(struct entrypoint *ep, struct symbol *sym) complex = 0; FOR_EACH_PTR(pseudo->users, pu) { /* We know that the symbol-pseudo use is the "src" in the instruction */ - struct instruction *insn = pu->insn; - + struct instruction *insn; + if (!pu) + continue; + insn = pu->insn; switch (insn->opcode) { case OP_STORE: stores++; @@ -715,7 +719,10 @@ static void simplify_one_symbol(struct entrypoint *ep, struct symbol *sym) src = def->target; FOR_EACH_PTR(pseudo->users, pu) { - struct instruction *insn = pu->insn; + struct instruction *insn; + if (!pu) + continue; + insn = pu->insn; if (insn->opcode == OP_LOAD) { check_access(insn); convert_load_instruction(insn, src); @@ -731,7 +738,10 @@ complex_def: external_visibility: all = 1; FOR_EACH_PTR_REVERSE(pseudo->users, pu) { - struct instruction *insn = pu->insn; + struct instruction *insn; + if (!pu) + continue; + insn = pu->insn; if (insn->opcode == OP_LOAD) all &= find_dominating_stores(pseudo, insn, ++bb_generation, !mod); } END_FOR_EACH_PTR_REVERSE(pu); @@ -739,7 +749,10 @@ external_visibility: /* If we converted all the loads, remove the stores. They are dead */ if (all && !mod) { FOR_EACH_PTR(pseudo->users, pu) { - struct instruction *insn = pu->insn; + struct instruction *insn; + if (!pu) + continue; + insn = pu->insn; if (insn->opcode == OP_STORE) kill_store(insn); } END_FOR_EACH_PTR(pu); @@ -749,7 +762,10 @@ external_visibility: * of them.. */ FOR_EACH_PTR(pseudo->users, pu) { - struct instruction *insn = pu->insn; + struct instruction *insn; + if (!pu) + continue; + insn = pu->insn; if (insn->opcode == OP_STORE) kill_dominated_stores(pseudo, insn, ++bb_generation, insn->bb, !mod, 0); } END_FOR_EACH_PTR(pu); diff --git a/linearize.c b/linearize.c index ba76397ea..0933e935f 100644 --- a/linearize.c +++ b/linearize.c @@ -542,6 +542,8 @@ static void show_symbol_usage(pseudo_t pseudo) if (pseudo) { FOR_EACH_PTR(pseudo->users, pu) { + if (!pu) + continue; printf("\t%s\n", show_instruction(pu->insn)); } END_FOR_EACH_PTR(pu); } diff --git a/memops.c b/memops.c index aeacdf566..ce5aecbe8 100644 --- a/memops.c +++ b/memops.c @@ -66,7 +66,10 @@ static int address_taken(pseudo_t pseudo) { struct pseudo_user *pu; FOR_EACH_PTR(pseudo->users, pu) { - struct instruction *insn = pu->insn; + struct instruction *insn; + if (!pu) + continue; + insn = pu->insn; if (insn->bb && (insn->opcode != OP_LOAD && insn->opcode != OP_STORE)) return 1; } END_FOR_EACH_PTR(pu); diff --git a/simplify.c b/simplify.c index 03ff9c942..0569007a1 100644 --- a/simplify.c +++ b/simplify.c @@ -166,20 +166,24 @@ static int clean_up_phi(struct instruction *insn) return if_convert_phi(insn); } + static int delete_pseudo_user_list_entry(struct pseudo_user_list **list, pseudo_t *entry, int count) { struct pseudo_user *pu; FOR_EACH_PTR(*list, pu) { + if (!pu) + continue; if (pu->userp == entry) { - DELETE_CURRENT_PTR(pu); + MARK_CURRENT_DELETED(pu); if (!--count) goto out; } } END_FOR_EACH_PTR(pu); assert(count <= 0); out: - pack_ptr_list((struct ptr_list **)list); + if (ptr_list_size((struct ptr_list *) *list) == 0) + *list = NULL; return count; } @@ -308,6 +312,8 @@ static int dead_insn(struct instruction *insn, pseudo_t *src1, pseudo_t *src2, p { struct pseudo_user *pu; FOR_EACH_PTR(insn->target->users, pu) { + if (!pu) + continue; if (*pu->userp != VOID) return 0; } END_FOR_EACH_PTR(pu); diff --git a/unssa.c b/unssa.c index e7c9154d5..87d0c2c7f 100644 --- a/unssa.c +++ b/unssa.c @@ -58,6 +58,8 @@ static int simplify_phi_node(struct instruction *phi, pseudo_t tmp) // no need to make a copy of this one // -> replace the target pseudo by the tmp FOR_EACH_PTR(target->users, pu) { + if (!pu) + continue; use_pseudo(pu->insn, tmp, pu->userp); } END_FOR_EACH_PTR(pu);