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