13cab2bb3Spatrick //===-- int_util.h - internal utility functions ---------------------------===// 23cab2bb3Spatrick // 33cab2bb3Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 43cab2bb3Spatrick // See https://llvm.org/LICENSE.txt for license information. 53cab2bb3Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 63cab2bb3Spatrick // 73cab2bb3Spatrick //===----------------------------------------------------------------------===// 83cab2bb3Spatrick // 93cab2bb3Spatrick // This file is not part of the interface of this library. 103cab2bb3Spatrick // 113cab2bb3Spatrick // This file defines non-inline utilities which are available for use in the 123cab2bb3Spatrick // library. The function definitions themselves are all contained in int_util.c 133cab2bb3Spatrick // which will always be compiled into any compiler-rt library. 143cab2bb3Spatrick // 153cab2bb3Spatrick //===----------------------------------------------------------------------===// 163cab2bb3Spatrick 173cab2bb3Spatrick #ifndef INT_UTIL_H 183cab2bb3Spatrick #define INT_UTIL_H 193cab2bb3Spatrick 203cab2bb3Spatrick /// \brief Trigger a program abort (or panic for kernel code). 213cab2bb3Spatrick #define compilerrt_abort() __compilerrt_abort_impl(__FILE__, __LINE__, __func__) 223cab2bb3Spatrick 233cab2bb3Spatrick NORETURN void __compilerrt_abort_impl(const char *file, int line, 243cab2bb3Spatrick const char *function); 253cab2bb3Spatrick 263cab2bb3Spatrick #define COMPILE_TIME_ASSERT(expr) COMPILE_TIME_ASSERT1(expr, __COUNTER__) 273cab2bb3Spatrick #define COMPILE_TIME_ASSERT1(expr, cnt) COMPILE_TIME_ASSERT2(expr, cnt) 283cab2bb3Spatrick #define COMPILE_TIME_ASSERT2(expr, cnt) \ 293cab2bb3Spatrick typedef char ct_assert_##cnt[(expr) ? 1 : -1] UNUSED 303cab2bb3Spatrick 31*d89ec533Spatrick // Force unrolling the code specified to be repeated N times. 32*d89ec533Spatrick #define REPEAT_0_TIMES(code_to_repeat) /* do nothing */ 33*d89ec533Spatrick #define REPEAT_1_TIMES(code_to_repeat) code_to_repeat 34*d89ec533Spatrick #define REPEAT_2_TIMES(code_to_repeat) \ 35*d89ec533Spatrick REPEAT_1_TIMES(code_to_repeat) \ 36*d89ec533Spatrick code_to_repeat 37*d89ec533Spatrick #define REPEAT_3_TIMES(code_to_repeat) \ 38*d89ec533Spatrick REPEAT_2_TIMES(code_to_repeat) \ 39*d89ec533Spatrick code_to_repeat 40*d89ec533Spatrick #define REPEAT_4_TIMES(code_to_repeat) \ 41*d89ec533Spatrick REPEAT_3_TIMES(code_to_repeat) \ 42*d89ec533Spatrick code_to_repeat 43*d89ec533Spatrick 44*d89ec533Spatrick #define REPEAT_N_TIMES_(N, code_to_repeat) REPEAT_##N##_TIMES(code_to_repeat) 45*d89ec533Spatrick #define REPEAT_N_TIMES(N, code_to_repeat) REPEAT_N_TIMES_(N, code_to_repeat) 46*d89ec533Spatrick 473cab2bb3Spatrick #endif // INT_UTIL_H 48