Skip to content

Commit bdc5490

Browse files
committed
sys.h: Fix __attribute__ usage for non-GCC compilers
Restructure MLD_INLINE and MLD_ALWAYS_INLINE into separate blocks, each independently guarded: MLD_INLINE: - MSVC: __inline - C99 or inline macro: inline - GCC/Clang C90: __attribute__((unused)) to silence warnings - Other C90: empty MLD_ALWAYS_INLINE: - MSVC: __forceinline - GCC/Clang: MLD_INLINE __attribute__((always_inline)) - Other: MLD_INLINE This fixes two issues: 1. If `inline` was defined as a macro before including sys.h, the MSVC check was bypassed and __attribute__ was used, causing MSVC failures. 2. For non-MSVC/GCC/Clang compilers, __attribute__ was used unconditionally, causing build failures. Also fix typo: defined(clang) -> defined(__clang__) Signed-off-by: Matthias J. Kannwischer <[email protected]>
1 parent 060fdbd commit bdc5490

File tree

1 file changed

+26
-20
lines changed

1 file changed

+26
-20
lines changed

mldsa/src/sys.h

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -106,34 +106,40 @@
106106
#endif
107107

108108
/*
109-
* C90 does not have the inline compiler directive yet.
110-
* We don't use it in C90 builds.
111-
* However, in that case the compiler warns about some inline functions in
112-
* header files not being used in every compilation unit that includes that
113-
* header. To work around it we silence that warning in that case using
114-
* __attribute__((unused)).
109+
* MLD_INLINE: Hint for inlining.
110+
* - MSVC: __inline
111+
* - C99 or inline macro defined: inline
112+
* - GCC/Clang C90: __attribute__((unused)) to silence warnings
113+
* - Other C90: empty
115114
*/
116-
117-
/* Do not use inline for C90 builds*/
118115
#if !defined(MLD_INLINE)
119-
#if !defined(inline)
120116
#if defined(_MSC_VER)
121117
#define MLD_INLINE __inline
122-
/* Don't combine __inline and __forceinline */
123-
#define MLD_ALWAYS_INLINE __forceinline
124-
#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
118+
#elif defined(inline) || \
119+
(defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L)
125120
#define MLD_INLINE inline
126-
#define MLD_ALWAYS_INLINE MLD_INLINE __attribute__((always_inline))
127-
#else
121+
#elif defined(__GNUC__) || defined(__clang__)
128122
#define MLD_INLINE __attribute__((unused))
129-
#define MLD_ALWAYS_INLINE MLD_INLINE
123+
#else
124+
#define MLD_INLINE
130125
#endif
126+
#endif /* !MLD_INLINE */
131127

132-
#else /* !inline */
133-
#define MLD_INLINE inline
128+
/*
129+
* MLD_ALWAYS_INLINE: Force inlining.
130+
* - MSVC: __forceinline
131+
* - GCC/Clang: MLD_INLINE __attribute__((always_inline))
132+
* - Other: MLD_INLINE
133+
*/
134+
#if !defined(MLD_ALWAYS_INLINE)
135+
#if defined(_MSC_VER)
136+
#define MLD_ALWAYS_INLINE __forceinline
137+
#elif defined(__GNUC__) || defined(__clang__)
134138
#define MLD_ALWAYS_INLINE MLD_INLINE __attribute__((always_inline))
135-
#endif /* inline */
136-
#endif /* !MLD_INLINE */
139+
#else
140+
#define MLD_ALWAYS_INLINE MLD_INLINE
141+
#endif
142+
#endif /* !MLD_ALWAYS_INLINE */
137143

138144
#ifndef MLD_STATIC_TESTABLE
139145
#define MLD_STATIC_TESTABLE static
@@ -209,7 +215,7 @@
209215
} while (0)
210216
#endif /* !(MLD_CONFIG_CT_TESTING_ENABLED && !__ASSEMBLER__) */
211217

212-
#if defined(__GNUC__) || defined(clang)
218+
#if defined(__GNUC__) || defined(__clang__)
213219
#define MLD_MUST_CHECK_RETURN_VALUE __attribute__((warn_unused_result))
214220
#else
215221
#define MLD_MUST_CHECK_RETURN_VALUE

0 commit comments

Comments
 (0)