>> 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. 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...