https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123815
David Malcolm <dmalcolm at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Component|diagnostics |ipa
Assignee|dmalcolm at redhat dot com |unassigned at gcc dot
gnu.org
CC| |dmalcolm at gcc dot gnu.org
--- Comment #1 from David Malcolm <dmalcolm at gcc dot gnu.org> ---
(In reply to Jan Schultke from comment #0)
Thanks for filing this bug
> https://godbolt.org/z/81xP5nb1G
>
> [[gnu::always_inline]]
> static void f() {}
>
> <source>:2:13: warning: 'always_inline' function might not be inlinable
> unless also declared 'inline' [-Wattributes]
> 2 | static void f() {}
> | ^
>
>
> Is this warning actually correct? My intuition is that
> [[gnu::always_inline]] is meant to warn the user about misuses of the
> attribute, where they've applied the attribute to a function that cannot be
> inlined because its definition is not visible (in some contexts).
FWIW I think of it instead as a hint to the optimizer, along the lines of "when
I said 'inline', I really meant it".
That said, I had to look up the docs.
The docs here
https://www.gnu.org/software/c-intro-and-ref/manual/html_node/Attributes.html
say:
VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
always_inline
The always_inline attribute, in a function’s declaration or definition,
specifies to inline all calls to that function (unless something about the
function makes inlining impossible). This applies to all calls to that function
in a compilation unit where it has this attribute. See Inline Function
Definitions.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
whereas here
https://www.gnu.org/software/c-intro-and-ref/manual/html_node/Inline-Function-Definitions.html
say:
VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
You can force inlining of all calls to a given function that can be inlined,
even in a non-optimized compilation. by specifying the ‘always_inline’
attribute for the function, like this:
/* Prototype. */
inline void foo (const char) __attribute__((always_inline));
This is a GNU C extension. See Attributes in Declarations.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
whereas https://stackoverflow.com/a/48212527 says:
VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
The often referenced gcc documentation for always_inline is incomplete.
always_inline attribute makes gcc compiler:
[...various bullet points and commentary...]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> However, it is seemingly nonsensical to trigger the warning for a function
> with internal linkage whose body is visible. Why would such a function ever
> not be inlinable unless declared inline?
Not sure; the logic/heuristics for inlining are non-trivial and I'm not an
expert in this area; perhaps the "even in a non-optimized compilation" in the
2nd doc above might be the significant one here?
Reassigning to now to "ipa" component.
> The end result is that MANY correct
> (or harmless in practice) uses of [[gnu::always_inline]] are being flagged
> on -Wall when updating to GCC 15.
Is this leading to new warnings on a GCC 14 -> 15 migration?
Hope this is constructive