* [PATCH] fix missing checks for deleted instructions
@ 2018-02-11 9:21 Luc Van Oostenryck
0 siblings, 0 replies; only message in thread
From: Luc Van Oostenryck @ 2018-02-11 9:21 UTC (permalink / raw)
To: linux-sparse; +Cc: Luc Van Oostenryck
Instructions with a null ->bb are instructions which have
been killed. As such, they must thus always be ignored
but it's not always the case.
Fix this by adding a check for null ->bb where there is
some looping over all the instructions of a basic block.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
flow.c | 20 ++++++++++++++++----
validation/mem2reg/killed-insn.c | 15 +++++++++++++++
2 files changed, 31 insertions(+), 4 deletions(-)
create mode 100644 validation/mem2reg/killed-insn.c
diff --git a/flow.c b/flow.c
index e4c881d56..62658b920 100644
--- a/flow.c
+++ b/flow.c
@@ -164,6 +164,8 @@ static int bb_has_side_effects(struct basic_block *bb)
{
struct instruction *insn;
FOR_EACH_PTR(bb->insns, insn) {
+ if (!insn->bb)
+ continue;
switch (insn->opcode) {
case OP_CALL:
/* FIXME! This should take "const" etc into account */
@@ -396,6 +398,8 @@ static int find_dominating_parents(pseudo_t pseudo, struct instruction *insn,
FOR_EACH_PTR_REVERSE(parent->insns, one) {
int dominance;
+ if (!one->bb)
+ continue;
if (one == insn)
goto no_dominance;
dominance = dominates(pseudo, insn, one, local);
@@ -484,6 +488,8 @@ static int find_dominating_stores(pseudo_t pseudo, struct instruction *insn,
partial = 0;
FOR_EACH_PTR(bb->insns, one) {
int dominance;
+ if (!one->bb)
+ continue;
if (one == insn)
goto found;
dominance = dominates(pseudo, insn, one, local);
@@ -559,6 +565,8 @@ static void kill_dead_stores(pseudo_t pseudo, unsigned long generation, struct b
FOR_EACH_PTR_REVERSE(bb->insns, insn) {
int opcode = insn->opcode;
+ if (!insn->bb)
+ continue;
if (opcode != OP_LOAD && opcode != OP_STORE) {
if (local)
continue;
@@ -608,6 +616,8 @@ static void kill_dominated_stores(pseudo_t pseudo, struct instruction *insn,
bb->generation = generation;
FOR_EACH_PTR_REVERSE(bb->insns, one) {
int dominance;
+ if (!one->bb)
+ continue;
if (!found) {
if (one != insn)
continue;
@@ -777,6 +787,8 @@ void kill_bb(struct basic_block *bb)
struct basic_block *child, *parent;
FOR_EACH_PTR(bb->insns, insn) {
+ if (!insn->bb)
+ continue;
kill_instruction_force(insn);
kill_defs(insn);
/*
@@ -1022,10 +1034,10 @@ out:
kill_instruction(delete_last_instruction(&parent->insns));
FOR_EACH_PTR(bb->insns, insn) {
- if (insn->bb) {
- assert(insn->bb == bb);
- insn->bb = parent;
- }
+ if (!insn->bb)
+ continue;
+ assert(insn->bb == bb);
+ insn->bb = parent;
add_instruction(&parent->insns, insn);
} END_FOR_EACH_PTR(insn);
bb->insns = NULL;
diff --git a/validation/mem2reg/killed-insn.c b/validation/mem2reg/killed-insn.c
new file mode 100644
index 000000000..641525d3f
--- /dev/null
+++ b/validation/mem2reg/killed-insn.c
@@ -0,0 +1,15 @@
+static int g;
+static void foo(void)
+{
+ int a[2] = { };
+ a;
+ a[1] = g;
+}
+
+/*
+ * check-name: killed-insn
+ * check-command: test-linearize -fdump-ir=mem2reg $file
+ *
+ * check-output-ignore
+ * check-output-excludes: store\.
+ */
--
2.16.0
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2018-02-11 9:21 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-02-11 9:21 [PATCH] fix missing checks for deleted instructions Luc Van Oostenryck
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).