aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
-rw-r--r--linearize.c8
-rw-r--r--simplify.c4
-rw-r--r--validation/optim/trivial-phi01.c20
3 files changed, 26 insertions, 6 deletions
diff --git a/linearize.c b/linearize.c
index 8a3cf09b..9fecb4b5 100644
--- a/linearize.c
+++ b/linearize.c
@@ -1128,13 +1128,13 @@ static pseudo_t add_setfval(struct entrypoint *ep, struct symbol *ctype, long do
return target;
}
-static pseudo_t add_symbol_address(struct entrypoint *ep, struct symbol *sym)
+static pseudo_t add_symbol_address(struct entrypoint *ep, struct expression *expr)
{
- struct instruction *insn = alloc_instruction(OP_SYMADDR, bits_in_pointer);
+ struct instruction *insn = alloc_typed_instruction(OP_SYMADDR, expr->ctype);
pseudo_t target = alloc_pseudo(insn);
insn->target = target;
- use_pseudo(insn, symbol_pseudo(ep, sym), &insn->src);
+ use_pseudo(insn, symbol_pseudo(ep, expr->symbol), &insn->src);
add_one_insn(ep, insn);
return target;
}
@@ -1914,7 +1914,7 @@ static pseudo_t linearize_expression(struct entrypoint *ep, struct expression *e
switch (expr->type) {
case EXPR_SYMBOL:
linearize_one_symbol(ep, expr->symbol);
- return add_symbol_address(ep, expr->symbol);
+ return add_symbol_address(ep, expr);
case EXPR_VALUE:
return value_pseudo(expr->value);
diff --git a/simplify.c b/simplify.c
index fc64e5b7..334839a2 100644
--- a/simplify.c
+++ b/simplify.c
@@ -214,14 +214,14 @@ static pseudo_t trivial_phi(pseudo_t pseudo, struct instruction *insn, struct ps
src = def->phi_src; // bypass OP_PHISRC & get the real source
if (src == VOID)
continue;
+ if (src == target)
+ continue;
if (!pseudo) {
pseudo = src;
continue;
}
if (src == pseudo)
continue;
- if (src == target)
- continue;
if (DEF_OPCODE(def, src) == OP_PHI) {
if (pseudo_in_list(*list, src))
continue;
diff --git a/validation/optim/trivial-phi01.c b/validation/optim/trivial-phi01.c
new file mode 100644
index 00000000..40bd343b
--- /dev/null
+++ b/validation/optim/trivial-phi01.c
@@ -0,0 +1,20 @@
+void foo(int a)
+{
+ if (a) {
+ while (a) {
+ switch (0) {
+ default:
+ a = 0;
+ case 0:;
+ }
+ }
+ }
+}
+
+/*
+ * check-name: trivial-phi01
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-excludes: phi\\.
+ */