Skip to content

Commit

Permalink
Update stdckdint.h and make it available in pre-C23 modes. (#69649)
Browse files Browse the repository at this point in the history
The APIs and the feature test macro are both exposed. This is compatible
with how GCC is exposing the functionality.
  • Loading branch information
ZijunZhaoCCK committed Oct 25, 2023
1 parent 8715600 commit 7e34ee5
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ C23 Feature Support
- Clang now supports ``N3007 Type inference for object definitions``.

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

Non-comprehensive list of changes in this release
-------------------------------------------------
Expand Down
2 changes: 0 additions & 2 deletions clang/lib/Headers/stdckdint.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

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

#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
#define __STDC_VERSION_STDCKDINT_H__ 202311L

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

#endif /* __STDC_HOSTED__ */
#endif /* __STDCKDINT_H */
6 changes: 4 additions & 2 deletions clang/test/Headers/stdckdint.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 3
// RUN: %clang_cc1 -triple=x86_64 -emit-llvm -verify -std=c99 %s -o - | FileCheck %s
// RUN: %clang_cc1 -triple=x86_64 -emit-llvm -verify -std=c11 %s -o - | FileCheck %s
// RUN: %clang_cc1 -triple=x86_64 -emit-llvm -verify -std=c17 %s -o - | FileCheck %s
// RUN: %clang_cc1 -triple=x86_64 -emit-llvm -verify -std=c23 %s -o - | FileCheck %s

// expected-no-diagnostics

#include <stdbool.h>
#include <stdckdint.h>

_Static_assert(__STDC_VERSION_STDCKDINT_H__ == 202311L, "");

// CHECK-LABEL: define dso_local zeroext i1 @test_ckd_add(
// CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
// CHECK-NEXT: entry:
Expand Down

0 comments on commit 7e34ee5

Please sign in to comment.