summaryrefslogtreecommitdiff
path: root/include/linux/bug.h
blob: e25568c848bd443569d8e279bffba474eb763812 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#ifndef __TOOLS_LINUX_BUG_H
#define __TOOLS_LINUX_BUG_H

#include <assert.h>
#include <linux/compiler.h>

#define BUILD_BUG_ON_NOT_POWER_OF_2(n)			\
	BUILD_BUG_ON((n) == 0 || (((n) & ((n) - 1)) != 0))
#define BUILD_BUG_ON_ZERO(e)	(sizeof(struct { int:-!!(e); }))
#define BUILD_BUG_ON_NULL(e)	((void *)sizeof(struct { int:-!!(e); }))

#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))

#define BUG()			do { assert(0); unreachable(); } while (0)
#define BUG_ON(cond)		assert(!(cond))

#define WARN_ON_ONCE(cond)	({ bool _r = (cond); if (_r) assert(0); _r; })
#define WARN_ONCE(cond, msg)	({ bool _r = (cond); if (_r) assert(0); _r; })

#define __WARN()		assert(0)
#define __WARN_printf(arg...)	assert(0)
#define WARN(cond, ...)		assert(!(cond))

#define WARN_ON(condition) ({						\
	int __ret_warn_on = unlikely(!!(condition));			\
	if (__ret_warn_on)						\
		__WARN();						\
	__ret_warn_on;							\
})

#endif /* __TOOLS_LINUX_BUG_H */