Re: __attribute__ error ("message")

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On 02/04/2023 00:00, Jonathan Wakely wrote:
> 
> 
> On Sat, 1 Apr 2023, 17:58 Jonny Grant, <jg@xxxxxxxx <mailto:jg@xxxxxxxx>> wrote:
> 
> 
> 
>     On 31/03/2023 23:13, Xi Ruoyao wrote:
>     > On Fri, 2023-03-31 at 23:12 +0100, Jonny Grant wrote:
>     >>
>     >>
>     >> On 31/03/2023 22:58, Xi Ruoyao wrote:
>     >>> On Fri, 2023-03-31 at 22:54 +0100, Jonny Grant wrote:
>     >>>> If the error or warning attribute is used on a function
>     >>>> declaration
>     >>>> and a call to such a function is not eliminated through dead code
>     >>>> elimination or other optimizations, an error or warning
>     >>>> (respectively)
>     >>>> that includes message is diagnosed.
>     >>>
>     >>> In this example the "call to such a function" is clearly "eliminated
>     >>> through" inlining (one of "other optimizations").
>     >>>
>     >>>> https://godbolt.org/z/n849GPTjj <https://godbolt.org/z/n849GPTjj>
>     >>>
>     >>
>     >> ok yes, now I understand. The compile_abort() got inlined as abort().
>     >>
>     >> compile_abort():
>     >>         pushq   %rax
>     >>         call    abort
>     >> main:
>     >>         pushq   %rax
>     >>         call    abort
>     >>
>     >>
>     >> So if I implement it, I must avoid it being optimized (using pragma
>     >> etc as below)
>     >
>     > Or just __attribute__((noipa)).
> 
>     That's much clearer.
> 
>     It does feel a shame the optimizer inlines the function, discarding the error("message"), before the attribute error("message") can be triggered. But we can just put that __attribute__((noipa)) at least.
> 
> 
> Why provide a definition? Why do you want to define a function that can never be called, because calling it gives an error?

You make a good point. There's no need to define it, the declaration is enough to get the build error. Without the definition, it doesn't get inlined too.
Jonny




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux