From patchwork Wed Aug 9 19:37:59 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: 9891723 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 ED61A602D7 for ; Wed, 9 Aug 2017 19:39:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DF0FC2832D for ; Wed, 9 Aug 2017 19:39:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D3EC228500; Wed, 9 Aug 2017 19:39:01 +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 6FDDE2832D for ; Wed, 9 Aug 2017 19:39:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751914AbdHITjB (ORCPT ); Wed, 9 Aug 2017 15:39:01 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:33816 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751884AbdHITjA (ORCPT ); Wed, 9 Aug 2017 15:39:00 -0400 Received: by mail-wm0-f65.google.com with SMTP id x64so618115wmg.1 for ; Wed, 09 Aug 2017 12:38:59 -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=jXT6zLBhgcAQga6Ww4166mGecPPYlQ7fFpsTp6LCSCc=; b=H9j6egHZZog4gF4wmYsl1fPQ2UHUAWwf3/ZyLbzYCtxkmbzOck3PYIsT5SJotHP9dF KkXwEE6uk+THqWYsclFnisMoBiOaIk2UyuTSYn3lTFWS1ndUnoT46qKg2hKF8XkqInjp e3nYH6RZuoFwAjIjkaXQg1FtZEbRP2gee5ATWY3cDb5uWZfNgfoBIZ1J4vQF4WiHUqF6 OI9JwbLji/33sGADnY6ku524JYEgzc93LbtQrSkRDp1e5A1NM+85Y1gqEkqRwpFYWn7Y 1+t1/JZ5Z1qecttkmRpmJPZ5XovxxX6B60uhHNFfC0uzmtgWqMCIaAQEUZCg4Ok7S4Le gDaQ== 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=jXT6zLBhgcAQga6Ww4166mGecPPYlQ7fFpsTp6LCSCc=; b=p5LFqovgKaiikVx1a8TmhI+Kf22PRZaRz61T4s37RdvSlR0PUvtG6Jmk+HxbTEDgWh xiYIYbsJMb8r5wlV2nzoJjdY2suBz1FWDXUA9w9XxFYQV9IIcmxUlYj8M3sJU1mbK4Hh SAey5MBnMaa7zaQ+wqMSSsZ9Quv5M5RbsJ3kqKDZ75SW2KuO6d1mI9i+odpYkr29yWYv 7CpIpLzsTDqYWR9LSTCQs3acjpWmHvfs9WM3nRV9+o/4yUlk4UNOVmX77TK80J08t021 TkGKxPJ7o123nCBSvmPUPI5oJ7Eg0zTNtNlhl5xvJcW2bo28P9XrORHkNQbfsiZOCOIH TJUw== X-Gm-Message-State: AHYfb5imr5i0hTIbH8wIxcutpyyQQwfyAHq2P0DxJXT97y1E2kuXReFM u6PuWJULID5FnDK7FDs= X-Received: by 10.80.181.23 with SMTP id y23mr9029526edd.109.1502307539035; Wed, 09 Aug 2017 12:38:59 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:4076:600:a54f:2a42:70ce:5bd2]) by smtp.gmail.com with ESMTPSA id t36sm2984437edb.38.2017.08.09.12.38.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 09 Aug 2017 12:38:58 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Christopher Li , Luc Van Oostenryck Subject: [PATCH v4 2/9] Remove single-store shortcut Date: Wed, 9 Aug 2017 21:37:59 +0200 Message-Id: <20170809193806.30975-3-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.14.0 In-Reply-To: <20170809193806.30975-1-luc.vanoostenryck@gmail.com> References: <20170809193806.30975-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 patch will also avoid internal infinite loops occuring when processing undefined vars present during the SSA construction. Signed-off-by: Luc Van Oostenryck --- flow.c | 39 ++------------------------------------- validation/infinite-loop0.c | 1 - 2 files changed, 2 insertions(+), 38 deletions(-) diff --git a/flow.c b/flow.c index c7161d47e..5a3d55f76 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) { diff --git a/validation/infinite-loop0.c b/validation/infinite-loop0.c index a28492307..0e3e3805c 100644 --- a/validation/infinite-loop0.c +++ b/validation/infinite-loop0.c @@ -8,5 +8,4 @@ void foo(void) * check-name: internal infinite loop (0) * check-command: sparse -Wno-decl $file * check-timeout: - * check-known-to-fail */