Jose,

I appreciate the attempt.  But using the same 

#define ATTR_NORETURN_NOTHROW_LIST (ECF_NORETURN|ECF_NOTHROW)

as found in gcc/builtins.def make no difference.

Thanks, though.

Bob D.

> -----Original Message-----
> From: Jose E. Marchesi <jose.march...@oracle.com>
> Sent: Thursday, April 3, 2025 19:27
> To: Robert Dubner <rdub...@symas.com>
> Cc: GCC Mailing List <gcc@gcc.gnu.org>
> Subject: Re: COBOL: Call to builtin_decl_explicit (BUILT_IN_EXIT), is
> optimized away.
> 
> 
> Nah, I see ECF_TM_PURE despite the name seems to be doing something very
> different than ECF_CONST and ECF_PURE:
> 
>   if (flags & ECF_PURE)
>     DECL_PURE_P (decl) = 1;
>   ...
>   if ((flags & ECF_TM_PURE) && flag_tm)
>     apply_tm_attr (decl, get_identifier ("transaction_pure"));
> 
> Still, you may try to use the same ECF attributes than
gcc/builtins.def..
> 
> > Perhaps it is because you are using ECF_TM_PURE when defining the
> > built-in in cobol1.cc:
> >
> >   #define ATTR_TMPURE_NORETURN_NOTHROW_LEAF_COLD_LIST
> (ECF_TM_PURE|ECF_NORETURN|ECF_NOTHROW|ECF_LEAF|ECF_COLD)
> >
> >   [...]
> >   gfc_define_builtin ("__builtin_exit", ftype, BUILT_IN_EXIT,
> >           "exit", ATTR_TMPURE_NORETURN_NOTHROW_LEAF_COLD_LIST);
> >
> > In gcc/builtins.def:
> >
> >   DEF_LIB_BUILTIN        (BUILT_IN_EXIT, "exit", BT_FN_VOID_INT,
> ATTR_NORETURN_NOTHROW_LIST)
> >
> > So you want ECF_NORETURN and ECF_NOTHROW.
> >
> >> 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!

Reply via email to