xref: /netbsd-src/sys/external/bsd/common/include/linux/build_bug.h (revision b668e7f7240e49da35b4f789febbe6aed62d874f)
1*b668e7f7Sriastradh /*	$NetBSD: build_bug.h,v 1.4 2021/12/19 11:14:34 riastradh Exp $	*/
20006b9c8Sriastradh 
30006b9c8Sriastradh /*-
40006b9c8Sriastradh  * Copyright (c) 2020 The NetBSD Foundation, Inc.
50006b9c8Sriastradh  * All rights reserved.
60006b9c8Sriastradh  *
70006b9c8Sriastradh  * Redistribution and use in source and binary forms, with or without
80006b9c8Sriastradh  * modification, are permitted provided that the following conditions
90006b9c8Sriastradh  * are met:
100006b9c8Sriastradh  * 1. Redistributions of source code must retain the above copyright
110006b9c8Sriastradh  *    notice, this list of conditions and the following disclaimer.
120006b9c8Sriastradh  * 2. Redistributions in binary form must reproduce the above copyright
130006b9c8Sriastradh  *    notice, this list of conditions and the following disclaimer in the
140006b9c8Sriastradh  *    documentation and/or other materials provided with the distribution.
150006b9c8Sriastradh  *
160006b9c8Sriastradh  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
170006b9c8Sriastradh  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
180006b9c8Sriastradh  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
190006b9c8Sriastradh  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
200006b9c8Sriastradh  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
210006b9c8Sriastradh  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
220006b9c8Sriastradh  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
230006b9c8Sriastradh  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
240006b9c8Sriastradh  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
250006b9c8Sriastradh  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
260006b9c8Sriastradh  * POSSIBILITY OF SUCH DAMAGE.
270006b9c8Sriastradh  */
280006b9c8Sriastradh 
290006b9c8Sriastradh #ifndef	_LINUX_BUILD_BUG_H_
300006b9c8Sriastradh #define	_LINUX_BUILD_BUG_H_
310006b9c8Sriastradh 
320006b9c8Sriastradh #include <lib/libkern/libkern.h>
330006b9c8Sriastradh 
348a5e8a78Sriastradh /* Required to be false _or_ nonconstant.  */
358a5e8a78Sriastradh #define	BUILD_BUG_ON(EXPR)						      \
368a5e8a78Sriastradh 	CTASSERT(__builtin_choose_expr(__builtin_constant_p(EXPR), !(EXPR), 1))
370006b9c8Sriastradh 
388a5e8a78Sriastradh /* Required to be constant _and_ true.  XXX Should take optional message.  */
398a5e8a78Sriastradh #define	static_assert(EXPR)		CTASSERT(EXPR)
400006b9c8Sriastradh 
410006b9c8Sriastradh #define	BUILD_BUG()			do {} while (0)
428a5e8a78Sriastradh #define	BUILD_BUG_ON_MSG(EXPR,MSG)	BUILD_BUG_ON(EXPR)
430006b9c8Sriastradh #define	BUILD_BUG_ON_INVALID(EXPR)	((void)sizeof((long)(EXPR)))
44*b668e7f7Sriastradh #define	BUILD_BUG_ON_ZERO(EXPR)		((int)(0*sizeof(int[(EXPR) ? -1 : 1])))
450006b9c8Sriastradh 
460006b9c8Sriastradh #endif	/* _LINUX_BUILD_BUG_H_ */
47