[PATCH 11/11] return nothing only in void functions

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

 



Currently, the code for the return is only generated if the
effectively return a type or a value with a size greater than 0.

But this mean that a non-void function with an error in its return
expression is considered as a void function for what the generated
IR is concerned, making things incoherent.

Fix this by using the declared type instead of the type of the
return expression.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
---
 linearize.c                         | 6 +++---
 validation/linear/missing-return3.c | 1 -
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/linearize.c b/linearize.c
index 85dc9c94d..22a7a62f5 100644
--- a/linearize.c
+++ b/linearize.c
@@ -2002,7 +2002,7 @@ 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
+	if (!is_void_type(stmt->ret)) {			// non-void function
 		struct basic_block *active = ep->active;
 		if (active && !bb_terminated(active)) {	// missing return
 			struct basic_block *bb_ret;
@@ -2180,8 +2180,8 @@ static pseudo_t linearize_return(struct entrypoint *ep, struct statement *stmt)
 	struct basic_block *active;
 	pseudo_t src = linearize_expression(ep, expr);
 	active = ep->active;
-	if (active && src != VOID) {
-		add_return(ep, bb_return, expr->ctype, src);
+	if (active && !is_void_type(ret)) {
+		add_return(ep, bb_return, ret, src);
 	}
 	add_goto(ep, bb_return);
 	return VOID;
diff --git a/validation/linear/missing-return3.c b/validation/linear/missing-return3.c
index 57a03a737..b32e5eea8 100644
--- a/validation/linear/missing-return3.c
+++ b/validation/linear/missing-return3.c
@@ -11,7 +11,6 @@ static void ref(void)
 /*
  * check-name: missing-return3
  * check-command: sparse -vir -flinearize=last $file
- * check-known-to-fail
  *
  * check-error-start
 linear/missing-return3.c:4:17: error: return with no return value
-- 
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