Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 28 additions & 20 deletions mldsa/src/sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,34 +106,42 @@
#endif

/*
* C90 does not have the inline compiler directive yet.
* We don't use it in C90 builds.
* However, in that case the compiler warns about some inline functions in
* header files not being used in every compilation unit that includes that
* header. To work around it we silence that warning in that case using
* __attribute__((unused)).
* MLD_INLINE: Hint for inlining.
* - MSVC: __inline
* - C99+: inline
* - GCC/Clang C90: __attribute__((unused)) to silence warnings
* - Other C90: empty
*/

/* Do not use inline for C90 builds*/
#if !defined(MLD_INLINE)
#if !defined(inline)
#if defined(_MSC_VER)
#define MLD_INLINE __inline
/* Don't combine __inline and __forceinline */
#define MLD_ALWAYS_INLINE __forceinline
#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
#elif defined(inline) || \
(defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L)
#define MLD_INLINE inline
#define MLD_ALWAYS_INLINE MLD_INLINE __attribute__((always_inline))
#else
#elif defined(__GNUC__) || defined(__clang__)
#define MLD_INLINE __attribute__((unused))
#define MLD_ALWAYS_INLINE MLD_INLINE
#else
#define MLD_INLINE
#endif
#endif /* !MLD_INLINE */

#else /* !inline */
#define MLD_INLINE inline
/*
* MLD_ALWAYS_INLINE: Force inlining.
* - MSVC: __forceinline
* - GCC/Clang C99+: MLD_INLINE __attribute__((always_inline))
* - Other: MLD_INLINE (no forced inlining)
*/
#if !defined(MLD_ALWAYS_INLINE)
#if defined(_MSC_VER)
#define MLD_ALWAYS_INLINE __forceinline
#elif (defined(__GNUC__) || defined(__clang__)) && \
(defined(inline) || \
(defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L))
#define MLD_ALWAYS_INLINE MLD_INLINE __attribute__((always_inline))
#endif /* inline */
#endif /* !MLD_INLINE */
#else
#define MLD_ALWAYS_INLINE MLD_INLINE
#endif
#endif /* !MLD_ALWAYS_INLINE */

#ifndef MLD_STATIC_TESTABLE
#define MLD_STATIC_TESTABLE static
Expand Down Expand Up @@ -209,7 +217,7 @@
} while (0)
#endif /* !(MLD_CONFIG_CT_TESTING_ENABLED && !__ASSEMBLER__) */

#if defined(__GNUC__) || defined(clang)
#if defined(__GNUC__) || defined(__clang__)
#define MLD_MUST_CHECK_RETURN_VALUE __attribute__((warn_unused_result))
#else
#define MLD_MUST_CHECK_RETURN_VALUE
Expand Down