Commit | Line | Data |
---|---|---|
44d13f19 | 1 | /* |
c0c0989a | 2 | * SPDX-License-Identifier: MIT |
a60d70e6 | 3 | * |
c0c0989a | 4 | * Copyright (C) 2010-2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
44d13f19 MD |
5 | */ |
6 | ||
c0c0989a MJ |
7 | #ifndef _LTTNG_BUG_H |
8 | #define _LTTNG_BUG_H | |
9 | ||
3f12fcef MD |
10 | #include <urcu/compiler.h> |
11 | #include <stdio.h> | |
12 | #include <stdlib.h> | |
13 | ||
14 | #define LTTNG_BUG_ON(condition) \ | |
15 | do { \ | |
16 | if (caa_unlikely(condition)) { \ | |
17 | fprintf(stderr, \ | |
18 | "LTTng BUG in file %s, line %d.\n", \ | |
19 | __FILE__, __LINE__); \ | |
20 | exit(EXIT_FAILURE); \ | |
21 | } \ | |
22 | } while (0) | |
23 | ||
24 | #define LTTNG_BUILD_BUG_ON(condition) \ | |
a6352fd4 MD |
25 | ((void) sizeof(char[-!!(condition)])) |
26 | ||
44d13f19 | 27 | /** |
3f12fcef | 28 | * LTTNG_BUILD_RUNTIME_BUG_ON - check condition at build (if constant) or runtime |
44d13f19 MD |
29 | * @condition: the condition which should be false. |
30 | * | |
31 | * If the condition is a constant and true, the compiler will generate a build | |
32 | * error. If the condition is not constant, a BUG will be triggered at runtime | |
33 | * if the condition is ever true. If the condition is constant and false, no | |
34 | * code is emitted. | |
35 | */ | |
3f12fcef | 36 | #define LTTNG_BUILD_RUNTIME_BUG_ON(condition) \ |
44d13f19 MD |
37 | do { \ |
38 | if (__builtin_constant_p(condition)) \ | |
3f12fcef | 39 | LTTNG_BUILD_BUG_ON(condition); \ |
44d13f19 | 40 | else \ |
3f12fcef | 41 | LTTNG_BUG_ON(condition); \ |
44d13f19 MD |
42 | } while (0) |
43 | ||
44 | #endif |