From patchwork Tue Aug 8 23:06:27 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: 9889247 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 999AC60363 for ; Tue, 8 Aug 2017 23:07:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8BB972891C for ; Tue, 8 Aug 2017 23:07:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7AE5028951; Tue, 8 Aug 2017 23:07:06 +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 0EB7428A1D for ; Tue, 8 Aug 2017 23:07:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752510AbdHHXG4 (ORCPT ); Tue, 8 Aug 2017 19:06:56 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:36328 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752469AbdHHXGy (ORCPT ); Tue, 8 Aug 2017 19:06:54 -0400 Received: by mail-wm0-f68.google.com with SMTP id d40so4904065wma.3 for ; Tue, 08 Aug 2017 16:06:53 -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=9R59iFhF5tq5OjXPESjTbx3HfcrqZ3DNH/JoZbByvkg=; b=cCGy195qj39L8GrGnykhvaBnQ1WAy9ZGBgIl53ScFpcZMs3yLiee7dJIvDqnQ4cA5P CFoLCXdgquLTXV1HQgpJYRB38pkxE8Fk0HeoFKIZtAKMvYVefmIviHoHO7DYf7BPLILK HoLqpLbILNC8uP/nNOGIVMoMK8VDA2NFYLDqeRu8DXVJvPs+d2eCIw0A5PgTef5kJzzZ y3mvxjkAe29ZB1QDbAYyUcbuA0lrVPeDWukKcKC9V180CpM/70MP8G4q6cc9O4BRZGlM 7KA2mzvtUNXhSDsB2DU2xRLu5uwYXEzIivFwLFqug4tTsUgodmq3OXQgTv+kqVYakMuj vt7w== 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=9R59iFhF5tq5OjXPESjTbx3HfcrqZ3DNH/JoZbByvkg=; b=SWwLFbxXN8TNsxPqRztl9L2H+YDNK2iPYK5qMBt7Q+h7maty0eAvRU6T8KHZFPyoJs ULCXsnaUnHxdqEWxe0ueXLgpOBJ+amtatpN3QuW7SGKgYlYUmcvfXxGgtgRTkM6LjZbE BhinS5LxmxmnwYF/GBEGXqWubIIV1u6JMvKCEJcrOUDHETzj2AeD3u3yE/fDa1eXAyLJ zJxXg+WFhlKoP85uJ+864RdiviQCtqGMYhLhUQlKxNVYH98IaUuAQxLE1/Hk9M9L458m fwNjUIouFPRFMmFQM6ZVcmbjlB/eiRW7o4+NAZ+6gZY3tJ7EcVQ81R4XKZ4ro78pZgoC oJgw== X-Gm-Message-State: AHYfb5izw/K+7m4R4ps4+sJWKl+VUhq8Gg+H6oiaOHF/IXZPgSY6U/QQ PPjaW7v0E8eDCcsnSzU= X-Received: by 10.80.240.92 with SMTP id u28mr5950956edl.43.1502233612757; Tue, 08 Aug 2017 16:06:52 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:4076:600:6494:649b:1a34:f1b]) by smtp.gmail.com with ESMTPSA id n15sm1133490edb.87.2017.08.08.16.06.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 08 Aug 2017 16:06:52 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Christopher Li , Linus Torvalds , Dibyendu Majumdar , Luc Van Oostenryck Subject: [PATCH v3 1/8] Remove single-store shortcut Date: Wed, 9 Aug 2017 01:06:27 +0200 Message-Id: <20170808230634.16227-2-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.13.2 In-Reply-To: <20170808230634.16227-1-luc.vanoostenryck@gmail.com> References: <20170808230634.16227-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 not initialize them, maybe by error, but they can also occurs when they are only set (and used) in a single path or even worse, hen initiializing a bitfield. The origin of the problem 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. Note: this will also solve most infinite loops that can happen when processing undefined vars. 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) {