| 1 | /* |
| 2 | * SPDX-License-Identifier: MIT |
| 3 | * |
| 4 | * Copyright (C) 2010-2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
| 5 | */ |
| 6 | |
| 7 | #ifndef _LTTNG_UST_BUG_H |
| 8 | #define _LTTNG_UST_BUG_H |
| 9 | |
| 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) \ |
| 25 | ((void) sizeof(char[-!!(condition)])) |
| 26 | |
| 27 | /** |
| 28 | * LTTNG_BUILD_RUNTIME_BUG_ON - check condition at build (if constant) or runtime |
| 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 | */ |
| 36 | #define LTTNG_BUILD_RUNTIME_BUG_ON(condition) \ |
| 37 | do { \ |
| 38 | if (__builtin_constant_p(condition)) \ |
| 39 | LTTNG_BUILD_BUG_ON(condition); \ |
| 40 | else \ |
| 41 | LTTNG_BUG_ON(condition); \ |
| 42 | } while (0) |
| 43 | |
| 44 | #endif |