Skip to content
Snippets Groups Projects
Commit c5b0c22b authored by xleroy's avatar xleroy
Browse files

cparser/AddCasts.ml: forgot to materialize cast at return statement.

git-svn-id: https://yquem.inria.fr/compcert/svn/compcert/trunk@1307 fca1b0fc-160b-0410-b1d3-a4f43f01ea2e
parent 6f731da1
No related branches found
No related tags found
No related merge requests found
......@@ -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' }
......
......@@ -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 \
......
7616
226
#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;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment