I will try again. First, the explicit call to "exit" is also being optimized away.
Second, grepping indicates I am the only one in GCC trying to use BUILT_IN_EXIT. So, let me rephrase: What GENERIC do I have to create that will do the equivalent of calling exit() in a C program? Thanks. > -----Original Message----- > From: Gcc <gcc-bounces~rdubner=symas....@gcc.gnu.org> On Behalf Of Robert > Dubner > Sent: Thursday, April 3, 2025 18:19 > To: GCC Mailing List <gcc@gcc.gnu.org> > Subject: RE: COBOL: Call to builtin_decl_explicit (BUILT_IN_EXIT), is > optimized away. > > 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!