Fix BUG_ON handling
[lttng-ust.git] / include / lttng / bug.h
1 #ifndef _LTTNG_BUG_H
2 #define _LTTNG_BUG_H
3
4 /*
5 * lttng/bug.h
6 *
7 * (C) Copyright 2010-2011 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 *
9 * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
10 * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
11 *
12 * Permission is hereby granted to use or copy this program
13 * for any purpose, provided the above notices are retained on all copies.
14 * Permission to modify the code and to distribute modified code is granted,
15 * provided the above notices are retained, and a notice that the code was
16 * modified is included with the above copyright notice.
17 */
18
19 #include <urcu/compiler.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22
23 #define LTTNG_BUG_ON(condition) \
24 do { \
25 if (caa_unlikely(condition)) { \
26 fprintf(stderr, \
27 "LTTng BUG in file %s, line %d.\n", \
28 __FILE__, __LINE__); \
29 exit(EXIT_FAILURE); \
30 } \
31 } while (0)
32
33 #define LTTNG_BUILD_BUG_ON(condition) \
34 ((void) sizeof(char[-!!(condition)]))
35
36 /**
37 * LTTNG_BUILD_RUNTIME_BUG_ON - check condition at build (if constant) or runtime
38 * @condition: the condition which should be false.
39 *
40 * If the condition is a constant and true, the compiler will generate a build
41 * error. If the condition is not constant, a BUG will be triggered at runtime
42 * if the condition is ever true. If the condition is constant and false, no
43 * code is emitted.
44 */
45 #define LTTNG_BUILD_RUNTIME_BUG_ON(condition) \
46 do { \
47 if (__builtin_constant_p(condition)) \
48 LTTNG_BUILD_BUG_ON(condition); \
49 else \
50 LTTNG_BUG_ON(condition); \
51 } while (0)
52
53 #endif
This page took 0.031874 seconds and 5 git commands to generate.