All of lore.kernel.org
 help / color / mirror / Atom feed
From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: linux-sparse@vger.kernel.org
Cc: Christopher Li <sparse@chrisli.org>,
	Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Subject: [PATCH v5 12/51] llvm: fix output_op_store() which modify its operand
Date: Sat, 25 Mar 2017 00:20:18 +0100	[thread overview]
Message-ID: <20170324232057.15033-13-luc.vanoostenryck@gmail.com> (raw)
In-Reply-To: <20170324232057.15033-1-luc.vanoostenryck@gmail.com>

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 <mobile@majumdar.org.uk>
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 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 94ebc9577..e01406281 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.
+ */
-- 
2.12.0


  parent reply	other threads:[~2017-03-24 23:23 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-24 23:20 [PATCH v5 00/51] LLVM fixes Luc Van Oostenryck
2017-03-24 23:20 ` [PATCH v5 01/51] llvm: remove unneeded arg 'module' Luc Van Oostenryck
2017-03-24 23:20 ` [PATCH v5 02/51] llvm: remove unneeded 'generation' Luc Van Oostenryck
2017-03-24 23:20 ` [PATCH v5 03/51] llvm: remove unneeded function::type Luc Van Oostenryck
2017-03-24 23:20 ` [PATCH v5 04/51] llvm: reduce scope of 'bb_nr' Luc Van Oostenryck
2017-03-24 23:20 ` [PATCH v5 05/51] llvm: use pseudo_list_size() instead of open coding it Luc Van Oostenryck
2017-03-24 23:20 ` [PATCH v5 06/51] llvm: give arguments a name Luc Van Oostenryck
2017-03-24 23:20 ` [PATCH v5 07/51] llvm: give a name to call's return values Luc Van Oostenryck
2017-03-24 23:20 ` [PATCH v5 08/51] llvm: avoid useless temp variable Luc Van Oostenryck
2017-03-24 23:20 ` [PATCH v5 09/51] llvm: extract get_sym_value() from pseudo_to_value() Luc Van Oostenryck
2017-03-24 23:20 ` [PATCH v5 10/51] llvm: fix test of floating-point type Luc Van Oostenryck
2017-03-24 23:20 ` [PATCH v5 11/51] llvm: fix translation of PSEUDO_VALs into a ValueRefs Luc Van Oostenryck
2017-03-24 23:20 ` Luc Van Oostenryck [this message]
2017-03-24 23:20 ` [PATCH v5 13/51] llvm: fix output_op_[ptr]cast() Luc Van Oostenryck
2017-03-24 23:20 ` [PATCH v5 14/51] llvm: take care of degenerated rvalues Luc Van Oostenryck
2017-03-24 23:20 ` [PATCH v5 15/51] llvm: add test cases for symbol's address Luc Van Oostenryck
2017-03-24 23:20 ` [PATCH v5 16/51] llvm: add test cases for pointers passed as argument Luc Van Oostenryck
2017-03-24 23:20 ` [PATCH v5 17/51] llvm: add test cases for arrays " Luc Van Oostenryck
2017-03-24 23:20 ` [PATCH v5 18/51] llvm: add test cases for degenerated pointers Luc Van Oostenryck
2017-03-24 23:20 ` [PATCH v5 19/51] llvm: add support for OP_NEG Luc Van Oostenryck
2017-03-24 23:20 ` [PATCH v5 20/51] llvm: add support for OP_SETVAL with floats Luc Van Oostenryck
2017-03-24 23:20 ` [PATCH v5 21/51] llvm: add support for OP_SETVAL with labels Luc Van Oostenryck
2017-03-24 23:20 ` [PATCH v5 22/51] llvm: ignore OP_INLINED_CALL Luc Van Oostenryck
2017-03-24 23:20 ` [PATCH v5 23/51] llvm: fix pointer/float mixup in comparisons Luc Van Oostenryck
2017-03-24 23:20 ` [PATCH v5 24/51] llvm: fix type in comparison with an address constant Luc Van Oostenryck
2017-03-24 23:20 ` [PATCH v5 25/51] llvm: give correct type to binops Luc Van Oostenryck
2017-03-24 23:20 ` [PATCH v5 26/51] llvm: adjust OP_RET's type Luc Van Oostenryck
2017-03-24 23:20 ` [PATCH v5 27/51] llvm: variadic functions are not being marked as such Luc Van Oostenryck
2017-03-24 23:20 ` [PATCH v5 28/51] llvm: fix type of switch constants Luc Van Oostenryck
2017-03-24 23:20 ` [PATCH v5 29/51] llvm: make pseudo_name() more flexible Luc Van Oostenryck
2017-03-24 23:20 ` [PATCH v5 30/51] llvm: give a name to all values Luc Van Oostenryck
2017-03-24 23:20 ` [PATCH v5 31/51] llvm: add support for OP_SWITCH with a range Luc Van Oostenryck
2017-03-24 23:20 ` [PATCH v5 32/51] llvm: fix OP_SWITCH has no target Luc Van Oostenryck
2017-03-24 23:20 ` [PATCH v5 33/51] llvm: make value_to_pvalue() more flexible Luc Van Oostenryck
2017-03-24 23:20 ` [PATCH v5 34/51] llvm: make value_to_ivalue() " Luc Van Oostenryck
2017-03-24 23:20 ` [PATCH v5 35/51] llvm: add test case pointer compare with cast Luc Van Oostenryck
2017-03-24 23:20 ` [PATCH v5 36/51] llvm: let pseudo_to_value() directly use the type Luc Van Oostenryck
2017-03-24 23:20 ` [PATCH v5 37/51] llvm: remove unneeded pseudo_to_value() unneeded argument Luc Van Oostenryck
2017-03-24 23:20 ` [PATCH v5 38/51] llvm: introduce get_ioperand() Luc Van Oostenryck
2017-03-24 23:20 ` [PATCH v5 39/51] llvm: fix mutating function pointer Luc Van Oostenryck
2017-03-24 23:20 ` [PATCH v5 40/51] llvm: fix mutated OP_RET Luc Van Oostenryck
2017-03-24 23:20 ` [PATCH v5 41/51] llvm: fix mutated OP_SEL Luc Van Oostenryck
2017-03-24 23:20 ` [PATCH v5 42/51] llvm: fix mutated OP_SWITCH Luc Van Oostenryck
2017-03-24 23:20 ` [PATCH v5 43/51] llvm: fix mutated OP_PHISOURCE Luc Van Oostenryck
2017-03-24 23:20 ` [PATCH v5 44/51] llvm: fix mutated OP_[PTR]CAST Luc Van Oostenryck
2017-03-24 23:20 ` [PATCH v5 45/51] llvm: add support for restricted types Luc Van Oostenryck
2017-03-24 23:20 ` [PATCH v5 46/51] llvm: fix get value from initialized symbol Luc Van Oostenryck
2017-03-24 23:20 ` [PATCH v5 47/51] llvm: fix get value from non-anonymous symbol Luc Van Oostenryck
2017-03-24 23:20 ` [PATCH v5 48/51] llvm: fix type of bitfields Luc Van Oostenryck
2017-03-24 23:20 ` [PATCH v5 49/51] llvm: add support for OP_FPCAST Luc Van Oostenryck
2017-03-24 23:20 ` [PATCH v5 50/51] llvm: add support for cast from floats Luc Van Oostenryck
2017-03-24 23:20 ` [PATCH v5 51/51] llvm: cleanup of output_[ptr]cast() Luc Van Oostenryck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170324232057.15033-13-luc.vanoostenryck@gmail.com \
    --to=luc.vanoostenryck@gmail.com \
    --cc=linux-sparse@vger.kernel.org \
    --cc=sparse@chrisli.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.