xref: /llvm-project/compiler-rt/lib/builtins/int_util.h (revision 0e90d8d4fed8c8cac70700acfdef6fc2ca2d482d)
10ba22f51SPetr Hosek //===-- int_util.h - internal utility functions ---------------------------===//
20ba22f51SPetr Hosek //
30ba22f51SPetr Hosek // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40ba22f51SPetr Hosek // See https://llvm.org/LICENSE.txt for license information.
50ba22f51SPetr Hosek // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60ba22f51SPetr Hosek //
70ba22f51SPetr Hosek //===----------------------------------------------------------------------===//
80ba22f51SPetr Hosek //
90ba22f51SPetr Hosek // This file is not part of the interface of this library.
100ba22f51SPetr Hosek //
110ba22f51SPetr Hosek // This file defines non-inline utilities which are available for use in the
120ba22f51SPetr Hosek // library. The function definitions themselves are all contained in int_util.c
130ba22f51SPetr Hosek // which will always be compiled into any compiler-rt library.
140ba22f51SPetr Hosek //
150ba22f51SPetr Hosek //===----------------------------------------------------------------------===//
16a6b264b5SAlexey Samsonov 
17a6b264b5SAlexey Samsonov #ifndef INT_UTIL_H
18a6b264b5SAlexey Samsonov #define INT_UTIL_H
19a6b264b5SAlexey Samsonov 
200ba22f51SPetr Hosek /// \brief Trigger a program abort (or panic for kernel code).
214357ca65SRichard Smith #define compilerrt_abort() __compilerrt_abort_impl(__FILE__, __LINE__, __func__)
22a6b264b5SAlexey Samsonov 
234357ca65SRichard Smith NORETURN void __compilerrt_abort_impl(const char *file, int line,
24e6f9652aSSaleem Abdulrasool                                       const char *function);
25a6b264b5SAlexey Samsonov 
264814b9c9SChih-Hung Hsieh #define COMPILE_TIME_ASSERT(expr) COMPILE_TIME_ASSERT1(expr, __COUNTER__)
274814b9c9SChih-Hung Hsieh #define COMPILE_TIME_ASSERT1(expr, cnt) COMPILE_TIME_ASSERT2(expr, cnt)
284814b9c9SChih-Hung Hsieh #define COMPILE_TIME_ASSERT2(expr, cnt)                                        \
29e6f9652aSSaleem Abdulrasool   typedef char ct_assert_##cnt[(expr) ? 1 : -1] UNUSED
304814b9c9SChih-Hung Hsieh 
31*0e90d8d4SAnatoly Trosinenko // Force unrolling the code specified to be repeated N times.
32*0e90d8d4SAnatoly Trosinenko #define REPEAT_0_TIMES(code_to_repeat) /* do nothing */
33*0e90d8d4SAnatoly Trosinenko #define REPEAT_1_TIMES(code_to_repeat) code_to_repeat
34*0e90d8d4SAnatoly Trosinenko #define REPEAT_2_TIMES(code_to_repeat)                                         \
35*0e90d8d4SAnatoly Trosinenko   REPEAT_1_TIMES(code_to_repeat)                                               \
36*0e90d8d4SAnatoly Trosinenko   code_to_repeat
37*0e90d8d4SAnatoly Trosinenko #define REPEAT_3_TIMES(code_to_repeat)                                         \
38*0e90d8d4SAnatoly Trosinenko   REPEAT_2_TIMES(code_to_repeat)                                               \
39*0e90d8d4SAnatoly Trosinenko   code_to_repeat
40*0e90d8d4SAnatoly Trosinenko #define REPEAT_4_TIMES(code_to_repeat)                                         \
41*0e90d8d4SAnatoly Trosinenko   REPEAT_3_TIMES(code_to_repeat)                                               \
42*0e90d8d4SAnatoly Trosinenko   code_to_repeat
43*0e90d8d4SAnatoly Trosinenko 
44*0e90d8d4SAnatoly Trosinenko #define REPEAT_N_TIMES_(N, code_to_repeat) REPEAT_##N##_TIMES(code_to_repeat)
45*0e90d8d4SAnatoly Trosinenko #define REPEAT_N_TIMES(N, code_to_repeat) REPEAT_N_TIMES_(N, code_to_repeat)
46*0e90d8d4SAnatoly Trosinenko 
470ba22f51SPetr Hosek #endif // INT_UTIL_H
48