[clang] 7e34ee5 - Update stdckdint.h and make it available in pre-C23 modes. (#69649)

via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 25 11:04:35 PDT 2023


Author: ZijunZhaoCCK
Date: 2023-10-25T11:04:31-07:00
New Revision: 7e34ee5291b935a1e37cd1b132552187d5c784d0

URL: https://github.com/llvm/llvm-project/commit/7e34ee5291b935a1e37cd1b132552187d5c784d0
DIFF: https://github.com/llvm/llvm-project/commit/7e34ee5291b935a1e37cd1b132552187d5c784d0.diff

LOG: Update stdckdint.h and make it available in pre-C23 modes. (#69649)

The APIs and the feature test macro are both exposed. This is compatible
with how GCC is exposing the functionality.

Added: 
    

Modified: 
    clang/docs/ReleaseNotes.rst
    clang/lib/Headers/stdckdint.h
    clang/test/Headers/stdckdint.c

Removed: 
    


################################################################################
diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f94e4e10b805911..42f20b9a9bb0410 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -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
 -------------------------------------------------

diff  --git a/clang/lib/Headers/stdckdint.h b/clang/lib/Headers/stdckdint.h
index 22972d78d9077a4..20bc34ffb30235c 100644
--- a/clang/lib/Headers/stdckdint.h
+++ b/clang/lib/Headers/stdckdint.h
@@ -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-
@@ -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 */

diff  --git a/clang/test/Headers/stdckdint.c b/clang/test/Headers/stdckdint.c
index 896c740360065b6..6b6d74a89d4c111 100644
--- a/clang/test/Headers/stdckdint.c
+++ b/clang/test/Headers/stdckdint.c
@@ -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:


        


More information about the cfe-commits mailing list