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