Skip to content

Commit eb5c2d4

Browse files
committed
compiler.h: Move compiletime_assert() macros into compiler_types.h
The kernel test robot reports that moving READ_ONCE() out into its own header breaks a W=1 build for parisc, which is relying on the definition of compiletime_assert() being available: | In file included from ./arch/parisc/include/generated/asm/rwonce.h:1, | from ./include/asm-generic/barrier.h:16, | from ./arch/parisc/include/asm/barrier.h:29, | from ./arch/parisc/include/asm/atomic.h:11, | from ./include/linux/atomic.h:7, | from kernel/locking/percpu-rwsem.c:2: | ./arch/parisc/include/asm/atomic.h: In function 'atomic_read': | ./include/asm-generic/rwonce.h:36:2: error: implicit declaration of function 'compiletime_assert' [-Werror=implicit-function-declaration] | 36 | compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long), \ | | ^~~~~~~~~~~~~~~~~~ | ./include/asm-generic/rwonce.h:49:2: note: in expansion of macro 'compiletime_assert_rwonce_type' | 49 | compiletime_assert_rwonce_type(x); \ | | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ./arch/parisc/include/asm/atomic.h:73:9: note: in expansion of macro 'READ_ONCE' | 73 | return READ_ONCE((v)->counter); | | ^~~~~~~~~ Move these macros into compiler_types.h, so that they are available to READ_ONCE() and friends. Link: http://lists.infradead.org/pipermail/linux-arm-kernel/2020-July/587094.html Reported-by: kernel test robot <[email protected]> Signed-off-by: Will Deacon <[email protected]>
1 parent ad83ec6 commit eb5c2d4

File tree

2 files changed

+41
-41
lines changed

2 files changed

+41
-41
lines changed

include/linux/compiler.h

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -273,47 +273,6 @@ static inline void *offset_to_ptr(const int *off)
273273

274274
#endif /* __ASSEMBLY__ */
275275

276-
/* Compile time object size, -1 for unknown */
277-
#ifndef __compiletime_object_size
278-
# define __compiletime_object_size(obj) -1
279-
#endif
280-
#ifndef __compiletime_warning
281-
# define __compiletime_warning(message)
282-
#endif
283-
#ifndef __compiletime_error
284-
# define __compiletime_error(message)
285-
#endif
286-
287-
#ifdef __OPTIMIZE__
288-
# define __compiletime_assert(condition, msg, prefix, suffix) \
289-
do { \
290-
extern void prefix ## suffix(void) __compiletime_error(msg); \
291-
if (!(condition)) \
292-
prefix ## suffix(); \
293-
} while (0)
294-
#else
295-
# define __compiletime_assert(condition, msg, prefix, suffix) do { } while (0)
296-
#endif
297-
298-
#define _compiletime_assert(condition, msg, prefix, suffix) \
299-
__compiletime_assert(condition, msg, prefix, suffix)
300-
301-
/**
302-
* compiletime_assert - break build and emit msg if condition is false
303-
* @condition: a compile-time constant condition to check
304-
* @msg: a message to emit if condition is false
305-
*
306-
* In tradition of POSIX assert, this macro will break the build if the
307-
* supplied condition is *false*, emitting the supplied error message if the
308-
* compiler has support to do so.
309-
*/
310-
#define compiletime_assert(condition, msg) \
311-
_compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
312-
313-
#define compiletime_assert_atomic_type(t) \
314-
compiletime_assert(__native_word(t), \
315-
"Need native word sized stores/loads for atomicity.")
316-
317276
/* &a[0] degrades to a pointer: a different type from an array */
318277
#define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0]))
319278

include/linux/compiler_types.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,47 @@ struct ftrace_likely_data {
300300
(sizeof(t) == sizeof(char) || sizeof(t) == sizeof(short) || \
301301
sizeof(t) == sizeof(int) || sizeof(t) == sizeof(long))
302302

303+
/* Compile time object size, -1 for unknown */
304+
#ifndef __compiletime_object_size
305+
# define __compiletime_object_size(obj) -1
306+
#endif
307+
#ifndef __compiletime_warning
308+
# define __compiletime_warning(message)
309+
#endif
310+
#ifndef __compiletime_error
311+
# define __compiletime_error(message)
312+
#endif
313+
314+
#ifdef __OPTIMIZE__
315+
# define __compiletime_assert(condition, msg, prefix, suffix) \
316+
do { \
317+
extern void prefix ## suffix(void) __compiletime_error(msg); \
318+
if (!(condition)) \
319+
prefix ## suffix(); \
320+
} while (0)
321+
#else
322+
# define __compiletime_assert(condition, msg, prefix, suffix) do { } while (0)
323+
#endif
324+
325+
#define _compiletime_assert(condition, msg, prefix, suffix) \
326+
__compiletime_assert(condition, msg, prefix, suffix)
327+
328+
/**
329+
* compiletime_assert - break build and emit msg if condition is false
330+
* @condition: a compile-time constant condition to check
331+
* @msg: a message to emit if condition is false
332+
*
333+
* In tradition of POSIX assert, this macro will break the build if the
334+
* supplied condition is *false*, emitting the supplied error message if the
335+
* compiler has support to do so.
336+
*/
337+
#define compiletime_assert(condition, msg) \
338+
_compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
339+
340+
#define compiletime_assert_atomic_type(t) \
341+
compiletime_assert(__native_word(t), \
342+
"Need native word sized stores/loads for atomicity.")
343+
303344
/* Helpers for emitting diagnostics in pragmas. */
304345
#ifndef __diag
305346
#define __diag(string)

0 commit comments

Comments
 (0)