aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2018-08-31 23:05:17 +0200
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2018-09-06 01:37:51 +0200
commit4885582d162e7b91616453957b3fe6d45eee5375 (patch)
treedd2ef22204943f5b19e9f716cb7521697bb3962e
parent51c6129e93fd26111211273dcd018426cf9df152 (diff)
downloadsparse-dev-4885582d162e7b91616453957b3fe6d45eee5375.tar.gz
return nothing only in void functions
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@gmail.com>
-rw-r--r--linearize.c6
-rw-r--r--validation/linear/missing-return3.c1
2 files changed, 3 insertions, 4 deletions
diff --git a/linearize.c b/linearize.c
index 85dc9c94..22a7a62f 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 57a03a73..b32e5eea 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