Skip to content

Conversation

@oldnewthing
Copy link
Member

Different toolchains use different ways of marking a function as not inlinable. Wrap it inside a macro so we can accommodate the differences.

Fortunately, all of them insert the marker at the same place (between the "inline" keyword and the return type).

Different toolchains use different ways of marking a function
as not inlinable. Wrap it inside a macro so we can accommodate
the differences.
@oldnewthing oldnewthing requested a review from kennykerr March 17, 2021 21:36
Comment on lines +48 to +54
#if defined(_MSC_VER)
#define WINRT_IMPL_NOINLINE __declspec(noinline)
#elif defined(__GNUC__)
#define WINRT_IMPL_NOINLINE __attribute__((noinline))
#else
#define WINRT_IMPL_NOINLINE
#endif
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this cover Clang? I believe clang already know how to interpret __declspec(noinline). I wouldn't want to degrade Clang inadvertently.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clang defines __GNUC__ and supports GNU-style __attribute__((noinline)). Clang has a (non-default) option to support MSVC-style __declspec(noinline) as well. This version removes the need to add the -fdeclspec flag when compiling with clang.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The breakdown is

Toolchain Special macros __declspec(noinline) __attribute__((noinline))
MSVC _MSC_VER
Clang (default) __GNUC__
__clang__
Clang (-fdeclspec) __GNUC__
__clang__
gcc __GNUC__
icc __GNUC__
__INTEL_COMPILER
icx __GNUC__
__INTEL_LLVM_COMPILER

djgpp, ellcc and zapcc are based on one of the above toolchains.

So sniffing for _MSC_VER and __GNUC__ covers all the major toolchains.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!

Copy link
Collaborator

@kennykerr kennykerr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@kennykerr kennykerr merged commit d61cb15 into master Mar 18, 2021
@kennykerr kennykerr deleted the noinline branch March 18, 2021 13:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants