Linux-Sparse Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] unop: fix access to defining instruction in simplify_unop()
@ 2020-10-06 16:43 Luc Van Oostenryck
  0 siblings, 0 replies; only message in thread
From: Luc Van Oostenryck @ 2020-10-06 16:43 UTC (permalink / raw)
  To: linux-sparse; +Cc: Luc Van Oostenryck

Only pseudos of type PSEUDO_REG have a defining instruction.

However, in commit 5425db10d4d3 ("simplify '~(~x)' and '-(-x)' to 'x'"),
this defining instruction of the 'src' of the outer unop
was accessed without checking the type.

Fixes: 5425db10d4d35895ba3ca390478c624233ec027d
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 simplify.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/simplify.c b/simplify.c
index 76c0558855a2..15452a585598 100644
--- a/simplify.c
+++ b/simplify.c
@@ -1311,13 +1311,11 @@ static int simplify_unop(struct instruction *insn)
 		struct instruction *def;
 
 	case OP_NOT:
-		def = insn->src->def;
-		if (def && def->opcode == OP_NOT)
+		if (DEF_OPCODE(def, insn->src) == OP_NOT)
 			return replace_with_pseudo(insn, def->src);
 		break;
 	case OP_NEG:
-		def = insn->src->def;
-		if (def && def->opcode == OP_NEG)
+		if (DEF_OPCODE(def, insn->src) == OP_NEG)
 			return replace_with_pseudo(insn, def->src);
 		break;
 	default:
-- 
2.28.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, back to index

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-06 16:43 [PATCH] unop: fix access to defining instruction in simplify_unop() Luc Van Oostenryck

Linux-Sparse Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-sparse/0 linux-sparse/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-sparse linux-sparse/ https://lore.kernel.org/linux-sparse \
		linux-sparse@vger.kernel.org
	public-inbox-index linux-sparse

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-sparse


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git