The COBOL compiler has this routine:
void
gg_exit(tree exit_code)
{
tree the_call =
build_call_expr_loc(location_from_lineno(),
builtin_decl_explicit (BUILT_IN_EXIT),
1,
exit_code);
gg_append_statement(the_call);
}
I have found that when GCOBOL is used with -O2, -O3, or -Os, the call to
gg_exit() is optimized away, and the intended exit value is lost, and I
end up with zero.
By changing the routine to
void
gg_exit(tree exit_code)
{
tree args[1] = {exit_code};
tree function = gg_get_function_address(INT, "exit");
tree the_call = build_call_array_loc (location_from_lineno(),
VOID,
function,
1,
args);
gg_append_statement(the_call);
}
the call is not optimized away, and the generated executable behaves as
expected.
How do I prevent the call to gg_exit() from being optimized away?
Thanks!