1*bed243d3SAndroid Build Coastguard Worker /*===---- stdckdint.h - Standard header for checking integer----------------=== 2*bed243d3SAndroid Build Coastguard Worker * 3*bed243d3SAndroid Build Coastguard Worker * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*bed243d3SAndroid Build Coastguard Worker * See https://llvm.org/LICENSE.txt for license information. 5*bed243d3SAndroid Build Coastguard Worker * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*bed243d3SAndroid Build Coastguard Worker * 7*bed243d3SAndroid Build Coastguard Worker *===-----------------------------------------------------------------------=== 8*bed243d3SAndroid Build Coastguard Worker */ 9*bed243d3SAndroid Build Coastguard Worker 10*bed243d3SAndroid Build Coastguard Worker #ifndef __STDCKDINT_H 11*bed243d3SAndroid Build Coastguard Worker #define __STDCKDINT_H 12*bed243d3SAndroid Build Coastguard Worker 13*bed243d3SAndroid Build Coastguard Worker /* If we're hosted, fall back to the system's stdckdint.h. FreeBSD, for 14*bed243d3SAndroid Build Coastguard Worker * example, already has a Clang-compatible stdckdint.h header. 15*bed243d3SAndroid Build Coastguard Worker * 16*bed243d3SAndroid Build Coastguard Worker * The `stdckdint.h` header requires C 23 or newer. 17*bed243d3SAndroid Build Coastguard Worker */ 18*bed243d3SAndroid Build Coastguard Worker #if __STDC_HOSTED__ && __has_include_next(<stdckdint.h>) 19*bed243d3SAndroid Build Coastguard Worker #include_next <stdckdint.h> 20*bed243d3SAndroid Build Coastguard Worker #else 21*bed243d3SAndroid Build Coastguard Worker 22*bed243d3SAndroid Build Coastguard Worker /* C23 7.20.1 Defines several macros for performing checked integer arithmetic*/ 23*bed243d3SAndroid Build Coastguard Worker 24*bed243d3SAndroid Build Coastguard Worker #define __STDC_VERSION_STDCKDINT_H__ 202311L 25*bed243d3SAndroid Build Coastguard Worker 26*bed243d3SAndroid Build Coastguard Worker // Both A and B shall be any integer type other than "plain" char, bool, a bit- 27*bed243d3SAndroid Build Coastguard Worker // precise integer type, or an enumerated type, and they need not be the same. 28*bed243d3SAndroid Build Coastguard Worker 29*bed243d3SAndroid Build Coastguard Worker // R shall be a modifiable lvalue of any integer type other than "plain" char, 30*bed243d3SAndroid Build Coastguard Worker // bool, a bit-precise integer type, or an enumerated type. It shouldn't be 31*bed243d3SAndroid Build Coastguard Worker // short type, either. Otherwise, it may be unable to hold two the result of 32*bed243d3SAndroid Build Coastguard Worker // operating two 'int's. 33*bed243d3SAndroid Build Coastguard Worker 34*bed243d3SAndroid Build Coastguard Worker // A diagnostic message will be produced if A or B are not suitable integer 35*bed243d3SAndroid Build Coastguard Worker // types, or if R is not a modifiable lvalue of a suitable integer type or R 36*bed243d3SAndroid Build Coastguard Worker // is short type. 37*bed243d3SAndroid Build Coastguard Worker #define ckd_add(R, A, B) __builtin_add_overflow((A), (B), (R)) 38*bed243d3SAndroid Build Coastguard Worker #define ckd_sub(R, A, B) __builtin_sub_overflow((A), (B), (R)) 39*bed243d3SAndroid Build Coastguard Worker #define ckd_mul(R, A, B) __builtin_mul_overflow((A), (B), (R)) 40*bed243d3SAndroid Build Coastguard Worker 41*bed243d3SAndroid Build Coastguard Worker #endif /* __STDC_HOSTED__ */ 42*bed243d3SAndroid Build Coastguard Worker #endif /* __STDCKDINT_H */ 43