On Tue, 2023-08-01 at 20:20 +0200, Jose E. Marchesi via Gcc wrote:
> 
> > > The Gambit Scheme->C compiler has an option to generate more
> > > efficient
> > > code if it knows that all tail and sibling calls in the generated
> > > C
> > > code will be optimized.  If gcc does not, however, optimize a
> > > tail or
> > > sibling call, the generated C code may be incorrect (depending on
> > > circumstances).
> > 
> > clang supports a musttail attribute that you use in return
> > statements.
> > But AFAIK GCC doesn't support it.  It would be nice if it did.
> 
> I looked around a little.
> 
> The GCC tree nodes for call expressions can be annotated as to
> require
> tail call optimization:
> 
>   /* Set on a CALL_EXPR if the call has been marked as requiring tail
> call
>      optimization for correctness.  */
>   #define CALL_EXPR_MUST_TAIL_CALL(NODE) \
>     (CALL_EXPR_CHECK (NODE)->base.static_flag)
> 
> And this is checked in many different places in calls.cc.  But at the
> moment the only way to set that flag is via a compiler plugin.  

Or from libgccjit.  FWIW I added it to support Scheme from libgccjit;
see this patch kit:
  https://gcc.gnu.org/ml/gcc-patches/2016-05/msg01287.html

Perhaps there's a case for a frontend attribute for this.
Dave

> An
> example of such a plugin is part of the GCC testsuite:
> 
>   testsuite/gcc.dg/plugin/must_tail_call_plugin.c
> 
> It may be possible to use a similar plugin in your Scheme-to-C
> compiler...
> 

Reply via email to