[Bug middle-end/115132] Sibling calls optim should not be performed when builtin_unwind_init is used

2024-05-17 Thread amonakov at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115132

Alexander Monakov  changed:

   What|Removed |Added

 CC||amonakov at gcc dot gnu.org

--- Comment #3 from Alexander Monakov  ---
Placing an empty asm is sufficient to prevent undesired tailcalls:

void gc ();

void foo (void)
{
  __builtin_unwind_init ();
  gc ();
  asm ("");
}

[Bug middle-end/115132] Sibling calls optim should not be performed when builtin_unwind_init is used

2024-05-17 Thread akrl at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115132

--- Comment #2 from akrl at gcc dot gnu.org ---
Hi Richard,

thanks, yes I tried that already, the trouble is that our code looks more like
this:

=
extern void flush_stack_call_func1 (void (*func) (void *arg), void *arg);
extern void mark_threads (void);
extern void
mark_threads_callback (void *ignore);

static inline void
flush_stack_call_func (void (*func) (void *arg), void *arg)
{
  __builtin_unwind_init ();
  flush_stack_call_func1 (func, arg);
}

void
mark_threads (void)
{
  flush_stack_call_func (mark_threads_callback, ((void *)0));
}

[...]
=

Because we have several places where 'flush_stack_call_func' is used.

Unfortunately as 'flush_stack_call_func' gets inlined the trick does not work.

I'm not ecstatic at making 'flush_stack_call_func' not inlinable nor at marking
all the functions where it is called with the attribute, but we'll have to find
a way anyway I guess.

Thanks

  Andrea

[Bug middle-end/115132] Sibling calls optim should not be performed when builtin_unwind_init is used

2024-05-17 Thread rguenth at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115132

--- Comment #1 from Richard Biener  ---
You can do the following as workaround:

void __attribute__((optimize("no-optimize-sibling-calls"))) foo (void)
{
  __builtin_unwind_init ();
  gc ();
}