Skip to content

Update stdckdint.h and make it available in pre-C23 modes. #69649

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Oct 25, 2023
Merged
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