Page MenuHomeFreeBSD

cdefs.h: add __inline to __always_inline
ClosedPublic

Authored by rlibby on Jun 23 2024, 4:53 PM.
Tags
None
Referenced Files
Unknown Object (File)
Oct 4 2024, 7:21 PM
Unknown Object (File)
Oct 4 2024, 5:16 PM
Unknown Object (File)
Oct 2 2024, 8:34 AM
Unknown Object (File)
Oct 2 2024, 5:21 AM
Unknown Object (File)
Sep 8 2024, 12:19 PM
Unknown Object (File)
Sep 8 2024, 2:11 AM
Unknown Object (File)
Sep 5 2024, 6:20 AM
Unknown Object (File)
Aug 30 2024, 7:50 PM
Subscribers
None

Details

Summary

Add inline to the always_inline macro to quiet dozens of gcc
warnings of the form:
warning: 'always_inline' function might not be inlinable [-Wattributes]

It's clearly the intention of the __always_inline macro applied to a
function to inline the function. However, gcc seems to be picky with
the -Wattributes. It appears that __attribute__((__always_inline__))
was intended to apply to inline functions, as in, function declarations
with the attribute should also be declared as inline. Both clang and
gcc sources themselves use the two in combination:
inline __attribute__((__always_inline__))

FreeBSD sources mostly only use __always_inline, without the inline
keyword. Only a few files in libmsun used both.


Gcc refs:
https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html
https://gcc.gnu.org/onlinedocs/gcc/Inline.html
Clang ref:
https://clang.llvm.org/docs/AttributeReference.html


Another way to quiet the warnings could be to make all call sites do
inline __always_inline but this way made more sense to me.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

sys/sys/cdefs.h
268

I am sure that this should be __inline and not inline.

Is this used in .h file or .c files?

In D45711#1042461, @imp wrote:

Is this used in .h file or .c files?

Both, but it appears mostly .c in practice. Is there a reason we would want to restrict it?

sys/sys/cdefs.h
268

Okay. cdefs.h is strange. With __inline, we get the compiler alternate keyword, or else nothing, instead of the standard keyword, even when we are compiling for modern standard C. It will be fine with gcc and clang, I have no idea about others.

rlibby retitled this revision from cdefs.h: add inline to __always_inline to cdefs.h: add __inline to __always_inline.Jun 23 2024, 6:47 PM
rlibby edited the summary of this revision. (Show Details)
rlibby marked an inline comment as done.

kib: s/inline/__inline/

kib added inline comments.
sys/sys/cdefs.h
268

So this is a minor history from cdefs.h. But we must use __inline for headers, because we support C89 compilation.

This revision is now accepted and ready to land.Jun 24 2024, 3:02 AM
sys/sys/cdefs.h
268

I agree with kib. If we always add something, it should be __inline since that's always active (even in c89 mode) except for super duper weird compilers we may add support for in the future....

imp added inline comments.
sys/sys/cdefs.h
268

Though i imagine this will be rarely used in system headers

sys/sys/cdefs.h
268

Makes sense. Thanks.

This revision was automatically updated to reflect the committed changes.