On Mon, Oct 07, 2024 at 10:21:05AM +0300, Дилян Палаузов wrote:
> do you mean that optimizations for [[noreturn]] functions can only be done 
> when the functions are called from other TU?

No, but if it is static functions called from within the same TU, then the
[[noreturn]] attribute don't help, the compiler can discover that itself
(and if it can't, it wouldn't suggest it).

> How about a function with __attribute__ ((visibility ("hidden"))) during LTO 
> linking,
> aren’t there all functions considered more or less to be in the same TU?  Do 
> the [[noreturn]] optimizations still apply?

The [[noreturn]] optimizations apply always, if you call a function proven
to be noreturn (from attributes or callee analysis), then the compiler can
optimize away code after the call etc.
The attribute can be useful for non-static but hidden functions, callers
can be optimized earlier and don't rely on LTO propagation if user marks it
explicitly.

> What happens to a static [[noreturn]] function, if a pointer to it is passed 
> to other TU and that other TU calls the function?

Nothing.  [[noreturn]] attribute is function declaration attribute, it
doesn't apply to function pointers, so users can't mark a function pointer
to be function pointer to noreturn function; it will be only optimized
if the indirection is optimized out and turned into a direct call, then
the compiler knows whether it calls a noreturn function or not.
But, marking a static function [[noreturn]] even if you take a pointer
to it and pass to other TUs doesn't help in any way, the other TUs
will still see a function pointer which can't be marked and will not know
it will call only a noreturn function.

        Jakub

Reply via email to