[PATCH 09/11] use UNDEF for missing returns

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



If a return statement is missing in the last block, the
generated IR will be invalid because the number of operands
in the exit phi-node will not match the number or parent BBs.

Detect this situation and insert an UNDEF for the missing value.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
---
 linearize.c                         | 8 ++++++++
 validation/linear/missing-return0.c | 1 -
 validation/linear/missing-return1.c | 1 -
 validation/linear/missing-return2.c | 1 -
 validation/linear/missing-return4.c | 1 -
 validation/linear/missing-return5.c | 1 -
 6 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/linearize.c b/linearize.c
index 53d66ffa0..a631d0737 100644
--- a/linearize.c
+++ b/linearize.c
@@ -2002,6 +2002,14 @@ static pseudo_t linearize_fn_statement(struct entrypoint *ep, struct statement *
 	pseudo_t pseudo;
 
 	pseudo = linearize_compound_statement(ep, stmt);
+	if (type_size(stmt->ret) > 0) {			// non-void function
+		struct basic_block *active = ep->active;
+		if (active && !bb_terminated(active)) {	// missing return
+			struct basic_block *bb_ret;
+			bb_ret = get_bound_block(ep, stmt->ret);
+			add_return(ep, bb_ret, stmt->ret, undef_pseudo());
+		}
+	}
 	bb = add_label(ep, stmt->ret);
 	phi_node = first_instruction(bb->insns);
 	if (phi_node)
diff --git a/validation/linear/missing-return0.c b/validation/linear/missing-return0.c
index d6019941c..77ab5abd6 100644
--- a/validation/linear/missing-return0.c
+++ b/validation/linear/missing-return0.c
@@ -7,5 +7,4 @@ static int foo(int a)
 /*
  * check-name: missing-return0
  * check-command: sparse -vir -flinearize=last $file
- * check-known-to-fail
  */
diff --git a/validation/linear/missing-return1.c b/validation/linear/missing-return1.c
index c13135ada..4a8a9517d 100644
--- a/validation/linear/missing-return1.c
+++ b/validation/linear/missing-return1.c
@@ -12,5 +12,4 @@ static int foo(int a)
 /*
  * check-name: missing-return1
  * check-command: sparse -vir -flinearize=last $file
- * check-known-to-fail
  */
diff --git a/validation/linear/missing-return2.c b/validation/linear/missing-return2.c
index c1959b6f3..395dcc143 100644
--- a/validation/linear/missing-return2.c
+++ b/validation/linear/missing-return2.c
@@ -8,5 +8,4 @@ static int foo(int a)
 /*
  * check-name: missing-return2
  * check-command: sparse -vir -flinearize=last $file
- * check-known-to-fail
  */
diff --git a/validation/linear/missing-return4.c b/validation/linear/missing-return4.c
index dd30988b0..779893a0e 100644
--- a/validation/linear/missing-return4.c
+++ b/validation/linear/missing-return4.c
@@ -7,7 +7,6 @@ static int foo(int a)
 /*
  * check-name: missing-return4
  * check-command: test-linearize -Wno-decl $file
- * check-known-to-fail
  *
  * check-error-ignore
  * check-output-ignore
diff --git a/validation/linear/missing-return5.c b/validation/linear/missing-return5.c
index bcabd16a1..e5504a194 100644
--- a/validation/linear/missing-return5.c
+++ b/validation/linear/missing-return5.c
@@ -14,7 +14,6 @@ int bar(int p)
 /*
  * check-name: missing/undef return
  * check-command: test-linearize -Wno-decl -fdump-ir=linearize $file
- * check-known-to-fail
  *
  * check-output-ignore
  * check-output-pattern(2): phi\\..*,.*
-- 
2.18.0




[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux