diff --git a/cparser/AddCasts.ml b/cparser/AddCasts.ml
index 5ad5c63c812aa69440b68840d3b5213410bfdd87..9ec128d98e97a804d27f9cb4ead3af8c58290a0f 100644
--- a/cparser/AddCasts.ml
+++ b/cparser/AddCasts.ml
@@ -195,43 +195,43 @@ let add_decl env (sto, id, ty, optinit) =
 
 (* Statements *)
 
-let rec add_stmt env s =
+let rec add_stmt env f s =
   match s.sdesc with
   | Sskip -> s
   | Sdo e -> add_topexpr env s.sloc e
   | Sseq(s1, s2) -> 
-      {sdesc = Sseq(add_stmt env s1, add_stmt env s2); sloc = s.sloc }
+      {sdesc = Sseq(add_stmt env f s1, add_stmt env f s2); sloc = s.sloc }
   | Sif(e, s1, s2) ->
-      {sdesc = Sif(add_expr env e, add_stmt env s1, add_stmt env s2);
+      {sdesc = Sif(add_expr env e, add_stmt env f s1, add_stmt env f s2);
        sloc = s.sloc}
   | Swhile(e, s1) ->
-      {sdesc = Swhile(add_expr env e, add_stmt env s1);
+      {sdesc = Swhile(add_expr env e, add_stmt env f s1);
        sloc = s.sloc}
   | Sdowhile(s1, e) ->
-      {sdesc = Sdowhile(add_stmt env s1, add_expr env e);
+      {sdesc = Sdowhile(add_stmt env f s1, add_expr env e);
        sloc = s.sloc}
   | Sfor(s1, e, s2, s3) ->
-      {sdesc = Sfor(add_stmt env s1, add_expr env e, add_stmt env s2,
-                    add_stmt env s3);
+      {sdesc = Sfor(add_stmt env f s1, add_expr env e, add_stmt env f s2,
+                    add_stmt env f s3);
        sloc = s.sloc}
   | Sbreak -> s
   | Scontinue -> s
   | Sswitch(e, s1) ->
-      {sdesc = Sswitch(add_expr env e, add_stmt env s1); sloc = s.sloc}
+      {sdesc = Sswitch(add_expr env e, add_stmt env f s1); sloc = s.sloc}
   | Slabeled(lbl, s) ->
-      {sdesc = Slabeled(lbl, add_stmt env s); sloc = s.sloc}
+      {sdesc = Slabeled(lbl, add_stmt env f s); sloc = s.sloc}
   | Sgoto lbl -> s
   | Sreturn None -> s
   | Sreturn (Some e) ->
-      {sdesc = Sreturn(Some(add_expr env e)); sloc = s.sloc}
+      {sdesc = Sreturn(Some(cast env (add_expr env e) f.fd_ret)); sloc = s.sloc}
   | Sblock sl ->
-      {sdesc = Sblock(List.map (add_stmt env) sl); sloc = s.sloc}
+      {sdesc = Sblock(List.map (add_stmt env f) sl); sloc = s.sloc}
   | Sdecl d ->
       {sdesc = Sdecl(add_decl env d); sloc = s.sloc}
 
 let add_fundef env f =
   reset_temps();
-  let body' = add_stmt env f.fd_body in
+  let body' = add_stmt env f f.fd_body in
   let temps = get_temps () in
   (* fd_locals have no initializers, so no need to transform them *)
   { f with fd_locals = f.fd_locals @ temps; fd_body = body' }
diff --git a/test/regression/Makefile b/test/regression/Makefile
index a86f7d935cd87284bad6b1876d25936a01394e18..8407329f79ed7c6e58f95934151cb75c4f1568e2 100644
--- a/test/regression/Makefile
+++ b/test/regression/Makefile
@@ -7,7 +7,7 @@ CCOMPFLAGS=-stdlib ../../runtime -dparse -dclight -dasm \
 LIBS=$(LIBMATH)
 
 # Can run and have reference output in Results
-TESTS=bitfields1 expr1 initializers volatile2
+TESTS=bitfields1 expr1 initializers volatile2 funct3
 
 # Other tests: should compile to .s without errors (but expect warnings)
 EXTRAS=commaprec expr2 expr3 expr4 extern1 funct2 funptr1 init1 \
diff --git a/test/regression/Results/funct3 b/test/regression/Results/funct3
new file mode 100644
index 0000000000000000000000000000000000000000..62a2d00ad980cb974605593a8414ec341d3a6a98
--- /dev/null
+++ b/test/regression/Results/funct3
@@ -0,0 +1,2 @@
+7616
+226
diff --git a/test/regression/funct3.c b/test/regression/funct3.c
new file mode 100644
index 0000000000000000000000000000000000000000..8a1acded9c0a9960d7865d7968f2eb890b5e115a
--- /dev/null
+++ b/test/regression/funct3.c
@@ -0,0 +1,14 @@
+#include <stdio.h>
+
+unsigned char foo (unsigned short n)
+{
+  printf("%d\n", n);
+  return -30;
+}
+
+int main (void)
+{
+  int x = foo(-123456);
+  printf("%d\n", x);
+  return 0;
+}