Import CStringView from the Babeltrace tree
[lttng-tools.git] / src / common / bug.hpp
... / ...
CommitLineData
1/*
2 * Copyright (C) 2010-2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 */
7
8#ifndef _LTTNG_BUG_H
9#define _LTTNG_BUG_H
10
11#include <stdio.h>
12#include <stdlib.h>
13#include <urcu/compiler.h>
14
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 } \
21 } while (0)
22
23#define LTTNG_BUILD_BUG_ON(condition) ((void) sizeof(char[-!!(condition)]))
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 */
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); \
40 } while (0)
41
42#endif
This page took 0.021911 seconds and 4 git commands to generate.