Software APIs
dif_warn_unused_result.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_DIF_DIF_WARN_UNUSED_RESULT_H_
6 #define OPENTITAN_SW_DEVICE_LIB_DIF_DIF_WARN_UNUSED_RESULT_H_
7 
8 /**
9  * @file
10  * @brief Unused Result Warning Macro for DIFs.
11  */
12 
13 #ifdef __cplusplus
14 extern "C" {
15 #endif // __cplusplus
16 
17 /**
18  * Attribute for functions which return errors that must be acknowledged.
19  *
20  * This attribute must be used to mark all DIFs which return an error value of
21  * some kind, to ensure that callers do not accidentally drop the error on the
22  * ground.
23  *
24  * Normally, the standard way to drop such a value on the ground explicitly is
25  * with the syntax `(void)expr;`, in analogy with the behavior of C++'s
26  * `[[nodiscard]]` attribute.
27  * However, GCC does not implement this, so the idiom `if (expr) {}` should be
28  * used instead, for the time being.
29  * See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=25509.
30  */
31 #define DIF_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
32 
33 #ifdef __cplusplus
34 } // extern "C"
35 #endif // __cplusplus
36 
37 #endif // OPENTITAN_SW_DEVICE_LIB_DIF_DIF_WARN_UNUSED_RESULT_H_