Software APIs
assert.h
Go to the documentation of this file.
1 // Copyright lowRISC contributors.
2 // Licensed under the Apache License, Version 2.0, see LICENSE for details.
3 // SPDX-License-Identifier: Apache-2.0
4 
5 #ifndef OPENTITAN_SW_DEVICE_LIB_BASE_FREESTANDING_ASSERT_H_
6 #define OPENTITAN_SW_DEVICE_LIB_BASE_FREESTANDING_ASSERT_H_
7 
8 /**
9  * @file
10  * @brief C library diagnostics
11  *
12  * This header implements the assert.h standard header, specified in S7.2 of
13  * C11.
14  *
15  * While not required by S4p6 as part of freestanding C, this file is useful
16  * because it gives us a consistent spelling of `static_assert` across C and
17  * C++. `assert` should not be used in device code.
18  */
19 
20 // Note that `static_assert` is a C++ keyword, so we only need this to be
21 // defined for C.
22 #ifndef __cplusplus
23 #define static_assert _Static_assert
24 #endif // __cplusplus
25 
26 // `assert()` should not be used. When building with Clang, using this function
27 // in device code will emit a compile-time error.
28 #define assert(do_not_use) \
29  static_assert(false, "do not use assert(); use CHECK() instead")
30 
31 #endif // OPENTITAN_SW_DEVICE_LIB_BASE_FREESTANDING_ASSERT_H_