From patchwork Mon Aug 7 19:11:58 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: 9886041 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 DA4DF602CC for ; Mon, 7 Aug 2017 19:12:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CA58D2860A for ; Mon, 7 Aug 2017 19:12:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BF2C1286BF; Mon, 7 Aug 2017 19:12:13 +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 5B0932860A for ; Mon, 7 Aug 2017 19:12:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751921AbdHGTMN (ORCPT ); Mon, 7 Aug 2017 15:12:13 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:36356 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751508AbdHGTMM (ORCPT ); Mon, 7 Aug 2017 15:12:12 -0400 Received: by mail-wm0-f66.google.com with SMTP id d40so2047000wma.3 for ; Mon, 07 Aug 2017 12:12:11 -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=asiuG7kycYW+uM4n5QmtvZDrxkXzYE8Q7bCuv1/YpuM=; b=HrkRZ55zN9Zfn6wCVnmzrBfY2fxlV5KQVFFtZem9EXHkHA1otTZ0JIj4bAqDE/WUJR qG05MJ3HNFdWa09CjwQ2b6XdRI3vKTvxdHY5mNirkfFnFGRK5TGgk62SFVhrHirEgvz+ EAl7kZcFfrEmBXfPlYWfQSOkFFp+uJDn2QIOdZ7u0iwXZGPmhXkV79MFxrBapn8STM0l 3WkVjCx+BkGq6BQdALmBX9jbdBigr5fPsEgbPd3s4/8YF2XUEOcZTyNhzUoI5OINVwiP 0bBmLw/1l3uyymOuAMl8qZe7w7TqyVExbjZApUzAILPflvFIguNkEqnvL6TvtrXvkld4 8/GQ== 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=asiuG7kycYW+uM4n5QmtvZDrxkXzYE8Q7bCuv1/YpuM=; b=OdR8aIwhr86A2mwROwnxcrXjx1xw/kyDhX8/GPjkP0BEJmyQCRUAr7D/ZFxDzavIRA aI8LauZKEAgO2m8RXnnPxPPazgxeOZykthL86xu728wAAwjD098w8AhwWuvJ7tea1QQ7 THKVTurqdDuwTMM/w/1so5rNXyvnBK/dxPy2p5Oo27Vx7+9mtxHRUXLrWl3L8uTKRun2 aBRf/MNncV/j6WGH+xR5I02yZq2hvJ3BRO76AgxBjycRFcwv4l6r6v6hAGzrRqKq+90H pm7jtzHQlaWT4eBp5mY5FxIPnBe9ztQBIxrq7oYgwl7gvEn/yMHXkvopWJF+v5/EUzcH jOaA== X-Gm-Message-State: AHYfb5jQASavnj/xGq6baSQcGxWPOsg1rSnotkhB3ZKmltAs5DVdjJ4f OaVAEeBiqeWfmeqUw0c= X-Received: by 10.80.145.66 with SMTP id f2mr1894707eda.170.1502133131287; Mon, 07 Aug 2017 12:12:11 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:4076:600:29ff:6bdc:a0fa:4163]) by smtp.gmail.com with ESMTPSA id g52sm7742064edg.34.2017.08.07.12.12.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 07 Aug 2017 12:12:10 -0700 (PDT) From: Luc Van Oostenryck To: Dibyendu Majumdar Cc: linux-sparse@vger.kernel.org, Luc Van Oostenryck Subject: [PATCH v2 1/8] Remove single-store shortcut Date: Mon, 7 Aug 2017 21:11:58 +0200 Message-Id: <20170807191205.86590-2-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.13.2 In-Reply-To: <20170807191205.86590-1-luc.vanoostenryck@gmail.com> References: <20170807191205.86590-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 Current sparse code doesn't handle very gracefully code with undefined pseudos. These can occurs, of course because the dev has forgot (or choose) to initialize them but they can also occurs when they are only set (and used) in a single path and not others or even worse when initilaizing a bitfield. The origin of the problme is the single store shortcut in simplify_one_symbol() which doesn't take in account the (absence of) dominance when loads exist without stores. Fix this by removing this single-store shortcut and leave all the work for the general case which handle this situation quite well (and/but set those variables to 0). Warning: this change impact the performance. Signed-off-by: Luc Van Oostenryck --- flow.c | 39 ++------------------------------------- 1 file changed, 2 insertions(+), 37 deletions(-) diff --git a/flow.c b/flow.c index 6cac21b24..6b2c879a8 100644 --- a/flow.c +++ b/flow.c @@ -650,11 +650,10 @@ void check_access(struct instruction *insn) static void simplify_one_symbol(struct entrypoint *ep, struct symbol *sym) { - pseudo_t pseudo, src; + pseudo_t pseudo; struct pseudo_user *pu; - struct instruction *def; unsigned long mod; - int all, stores, complex; + int all; /* Never used as a symbol? */ pseudo = sym->pseudo; @@ -670,17 +669,12 @@ static void simplify_one_symbol(struct entrypoint *ep, struct symbol *sym) if (mod) goto external_visibility; - def = NULL; - stores = 0; - 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; switch (insn->opcode) { case OP_STORE: - stores++; - def = insn; break; case OP_LOAD: break; @@ -697,37 +691,8 @@ static void simplify_one_symbol(struct entrypoint *ep, struct symbol *sym) default: warning(sym->pos, "symbol '%s' pseudo used in unexpected way", show_ident(sym->ident)); } - complex |= insn->offset; } END_FOR_EACH_PTR(pu); - if (complex) - goto complex_def; - if (stores > 1) - goto multi_def; - - /* - * Goodie, we have a single store (if even that) in the whole - * thing. Replace all loads with moves from the pseudo, - * replace the store with a def. - */ - src = VOID; - if (def) - src = def->target; - - FOR_EACH_PTR(pseudo->users, pu) { - struct instruction *insn = pu->insn; - if (insn->opcode == OP_LOAD) { - check_access(insn); - convert_load_instruction(insn, src); - } - } END_FOR_EACH_PTR(pu); - - /* Turn the store into a no-op */ - kill_store(def); - return; - -multi_def: -complex_def: external_visibility: all = 1; FOR_EACH_PTR_REVERSE(pseudo->users, pu) {