Skip to content

Commit 7e34ee5

Browse files
authored
Update stdckdint.h and make it available in pre-C23 modes. (llvm#69649)
The APIs and the feature test macro are both exposed. This is compatible with how GCC is exposing the functionality.
1 parent 8715600 commit 7e34ee5

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ C23 Feature Support
185185
- Clang now supports ``N3007 Type inference for object definitions``.
186186

187187
- Clang now supports ``<stdckdint.h>`` which defines several macros for performing
188-
checked integer arithmetic.
188+
checked integer arithmetic. It is also exposed in pre-C23 modes.
189189

190190
Non-comprehensive list of changes in this release
191191
-------------------------------------------------

clang/lib/Headers/stdckdint.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
/* C23 7.20.1 Defines several macros for performing checked integer arithmetic*/
2323

24-
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
2524
#define __STDC_VERSION_STDCKDINT_H__ 202311L
2625

2726
// Both A and B shall be any integer type other than "plain" char, bool, a bit-
@@ -38,7 +37,6 @@
3837
#define ckd_add(R, A, B) __builtin_add_overflow((A), (B), (R))
3938
#define ckd_sub(R, A, B) __builtin_sub_overflow((A), (B), (R))
4039
#define ckd_mul(R, A, B) __builtin_mul_overflow((A), (B), (R))
41-
#endif
4240

4341
#endif /* __STDC_HOSTED__ */
4442
#endif /* __STDCKDINT_H */

clang/test/Headers/stdckdint.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 3
2+
// RUN: %clang_cc1 -triple=x86_64 -emit-llvm -verify -std=c99 %s -o - | FileCheck %s
3+
// RUN: %clang_cc1 -triple=x86_64 -emit-llvm -verify -std=c11 %s -o - | FileCheck %s
4+
// RUN: %clang_cc1 -triple=x86_64 -emit-llvm -verify -std=c17 %s -o - | FileCheck %s
25
// RUN: %clang_cc1 -triple=x86_64 -emit-llvm -verify -std=c23 %s -o - | FileCheck %s
36

47
// expected-no-diagnostics
58

9+
#include <stdbool.h>
610
#include <stdckdint.h>
711

8-
_Static_assert(__STDC_VERSION_STDCKDINT_H__ == 202311L, "");
9-
1012
// CHECK-LABEL: define dso_local zeroext i1 @test_ckd_add(
1113
// CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
1214
// CHECK-NEXT: entry:

0 commit comments

Comments
 (0)