I stated that poorly. After I generate the GENERIC, and I hand the tree over to the middle end, it is the call to BUILT_IN_EXIT that seems to be disappearing.
Everything I describe here is occurring with a -O0 build of GCC and GCOBOL. > -----Original Message----- > From: Robert Dubner <rdub...@symas.com> > Sent: Thursday, April 3, 2025 18:16 > To: 'GCC Mailing List' <gcc@gcc.gnu.org> > Cc: Robert Dubner <rdub...@symas.com> > Subject: COBOL: Call to builtin_decl_explicit (BUILT_IN_EXIT), is > optimized away. > > 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!