diff mbox

fix killing OP_SWITCH

Message ID 20180626224319.96586-1-luc.vanoostenryck@gmail.com (mailing list archive)
State Mainlined, archived
Headers show

Commit Message

Luc Van Oostenryck June 26, 2018, 10:43 p.m. UTC
Currently OP_SWITCHes are only handled by default in kill_insn().
In consequence, when killed, OP_SWITCHes leave a fake usage on the
condition.

Fix this by removing the condition's usage when killing an OP_SWITCH.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 simplify.c               |  1 +
 validation/kill-switch.c | 20 ++++++++++++++++++++
 2 files changed, 21 insertions(+)
 create mode 100644 validation/kill-switch.c
diff mbox

Patch

diff --git a/simplify.c b/simplify.c
index ad32fe08a..048f7c3aa 100644
--- a/simplify.c
+++ b/simplify.c
@@ -270,6 +270,7 @@  int kill_insn(struct instruction *insn, int force)
 		break;
 
 	case OP_CBR:
+	case OP_SWITCH:
 	case OP_COMPUTEDGOTO:
 		kill_use(&insn->cond);
 		break;
diff --git a/validation/kill-switch.c b/validation/kill-switch.c
new file mode 100644
index 000000000..f6b879b31
--- /dev/null
+++ b/validation/kill-switch.c
@@ -0,0 +1,20 @@ 
+static struct s {
+	unsigned f:1;
+} s;
+
+static void foo(void)
+{
+	switch (s.f) {
+	case 0:
+		;
+	}
+}
+
+/*
+ * check-name: kill-switch
+ * check-command: test-linearize $file
+ *
+ * check-output-ignore
+ * check-output-excludes: load\\.
+ * check-output-excludes: trunc\\.
+ */