From patchwork Mon Mar 27 21:23:36 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: 9647491 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 4433C60328 for ; Mon, 27 Mar 2017 21:26:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 35A8A28419 for ; Mon, 27 Mar 2017 21:26:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2ABBB2842E; Mon, 27 Mar 2017 21:26:45 +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 D035528419 for ; Mon, 27 Mar 2017 21:26:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752344AbdC0V0p (ORCPT ); Mon, 27 Mar 2017 17:26:45 -0400 Received: from mail-wr0-f196.google.com ([209.85.128.196]:33307 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752425AbdC0V0n (ORCPT ); Mon, 27 Mar 2017 17:26:43 -0400 Received: by mail-wr0-f196.google.com with SMTP id 20so17042151wrx.0 for ; Mon, 27 Mar 2017 14:26:42 -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=WBjGj3L7j3/s+C1OCDidJbj8dCjhELAY7tsSAePPMjI=; b=TMa7CeaIM2MCeq1wYQGeOF5bbXiafbPqnm9d2YKrLsFLR+j0q1OgWrmsV8ENihIMMm e1g6fYwHrBdop3SV6v+MA04LZT84jV8dKhAxmIhDQMqT0KZKRNrrHYGaqijeBLLI2vte sbdntv8TrFtHZTSxWUY4jcBfzfyKq32IJBwIDroy9kJ38obQ9kx1gt1Ls7okQg/NuoyZ SCo8SJr/KSonpBaWsj78REAkoD6ZBe2qNzqp2+3XLldmh1G7gcsA8wALthzdP4OMZC81 fOuB41yGldcnpFUgxDbIhNSzqhGd3k4nS7GsnEIb7z85J5n7AS3B8gWgG7j8gq/HXYpZ N63g== 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=WBjGj3L7j3/s+C1OCDidJbj8dCjhELAY7tsSAePPMjI=; b=QiLf9K7+xKczLmRpZpKNog4U3GHdt/z9qk06d4XC/IYvxJEB4tPtF/MTKM0/NFPpCV nNrAfKn6pKjejvj6JMGs8WkziAEzGMurwBH/l7UepjqIzrR4JEZMb/Q8WVd3f1ALqTC0 jBQpwvclMIen+xjFlD5vaQC702Vhar2Z2Jvoz9M2EoRWe846d+rT/rUPCYegjnyMSjOe GMQwM8Vc1kJ6+RNXueT38vIVF1fcHj1WfjA6nXS3va2dsRgMG3/5oTRsv65Px2GeItPF gMwlFWV48v7wTMvagJkZDDc7kZIGV6g2KPQNPn40XmpQCfBzQYKUKDEFCOq9o3vL4cRS Im6A== X-Gm-Message-State: AFeK/H1ofrr0ccuKJuPJifhWf7WkL1n3yXeLWVWmm6PTcq2GJ+uWDbgbYGZU7lhfmngRBA== X-Received: by 10.28.86.130 with SMTP id k124mr11326102wmb.58.1490649996522; Mon, 27 Mar 2017 14:26:36 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:802:b00:496:ae63:aebb:a034]) by smtp.gmail.com with ESMTPSA id k203sm973767wmk.4.2017.03.27.14.26.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 27 Mar 2017 14:26:36 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Christopher Li , Luc Van Oostenryck Subject: [PATCH v6 12/52] llvm: fix output_op_store() which modify its operand Date: Mon, 27 Mar 2017 23:23:36 +0200 Message-Id: <20170327212416.18536-13-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.12.0 In-Reply-To: <20170327212416.18536-1-luc.vanoostenryck@gmail.com> References: <20170327212416.18536-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 In sparse-llvm the field 'priv' of a pseudo is used to store the corresponding LLVMValueRef. This field is normaly assigned when processing the instruction that produces the speudo. In output_op_store(), the field insn->target->priv is overwritten by the LLVMValueRef returned by LLVMBuildStore(). It's unclear what this return value is: - this corrupts the pseudo, making it unusable in subsequent instructions. - there is no reason to change this field anyway. Fix this by removing the assignment to insn->target->priv in output_op_store(). Reported-by: Dibyendu Majumdar Signed-off-by: Luc Van Oostenryck --- sparse-llvm.c | 6 ++---- validation/backend/store-x2.c | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 validation/backend/store-x2.c diff --git a/sparse-llvm.c b/sparse-llvm.c index d0ae829f2..8894c2fa8 100644 --- a/sparse-llvm.c +++ b/sparse-llvm.c @@ -651,16 +651,14 @@ static void output_op_load(struct function *fn, struct instruction *insn) static void output_op_store(struct function *fn, struct instruction *insn) { - LLVMValueRef addr, target, target_in; + LLVMValueRef addr, target_in; addr = calc_memop_addr(fn, insn); target_in = pseudo_to_value(fn, insn, insn->target); /* perform store */ - target = LLVMBuildStore(fn->builder, target_in, addr); - - insn->target->priv = target; + LLVMBuildStore(fn->builder, target_in, addr); } static LLVMValueRef bool_value(struct function *fn, LLVMValueRef value) diff --git a/validation/backend/store-x2.c b/validation/backend/store-x2.c new file mode 100644 index 000000000..5ccc9b43a --- /dev/null +++ b/validation/backend/store-x2.c @@ -0,0 +1,16 @@ +void foo(int *p, int a, int b); +void foo(int *p, int a, int b) +{ + int c = a + b; + + p[0] = c; + p[1] = c; +} + +/* + * check-name: store-x2 + * check-command: sparsec -c $file -o tmp.o + * check-description: Verify in output_op_store() that + * the first store doesn't mess anymore with the + * 'target' and thus making the second store unusable. + */