blob: c372c2edc637137d28926ad9af948f31766907ba [file] [log] [blame]
Daniel Boulby318e7a52022-10-21 20:20:52 +01001//===-- int_util.h - internal utility functions ---------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file is not part of the interface of this library.
10//
11// This file defines non-inline utilities which are available for use in the
12// library. The function definitions themselves are all contained in int_util.c
13// which will always be compiled into any compiler-rt library.
14//
15//===----------------------------------------------------------------------===//
16
17#ifndef INT_UTIL_H
18#define INT_UTIL_H
19
20/// \brief Trigger a program abort (or panic for kernel code).
21#define compilerrt_abort() __compilerrt_abort_impl(__FILE__, __LINE__, __func__)
22
23NORETURN void __compilerrt_abort_impl(const char *file, int line,
24 const char *function);
25
26#define COMPILE_TIME_ASSERT(expr) COMPILE_TIME_ASSERT1(expr, __COUNTER__)
27#define COMPILE_TIME_ASSERT1(expr, cnt) COMPILE_TIME_ASSERT2(expr, cnt)
28#define COMPILE_TIME_ASSERT2(expr, cnt) \
29 typedef char ct_assert_##cnt[(expr) ? 1 : -1] UNUSED
30
31// Force unrolling the code specified to be repeated N times.
32#define REPEAT_0_TIMES(code_to_repeat) /* do nothing */
33#define REPEAT_1_TIMES(code_to_repeat) code_to_repeat
34#define REPEAT_2_TIMES(code_to_repeat) \
35 REPEAT_1_TIMES(code_to_repeat) \
36 code_to_repeat
37#define REPEAT_3_TIMES(code_to_repeat) \
38 REPEAT_2_TIMES(code_to_repeat) \
39 code_to_repeat
40#define REPEAT_4_TIMES(code_to_repeat) \
41 REPEAT_3_TIMES(code_to_repeat) \
42 code_to_repeat
43
44#define REPEAT_N_TIMES_(N, code_to_repeat) REPEAT_##N##_TIMES(code_to_repeat)
45#define REPEAT_N_TIMES(N, code_to_repeat) REPEAT_N_TIMES_(N, code_to_repeat)
46
47#endif // INT_UTIL_H