[Mlir-commits] [mlir] Update stdckdint.h and make it available in pre-C23 modes. (PR #69649)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Mon Oct 23 11:38:51 PDT 2023


https://github.com/ZijunZhaoCCK updated https://github.com/llvm/llvm-project/pull/69649

>From 0c57e45f6ee16e43cc6388b1ca6beb88bbc7b925 Mon Sep 17 00:00:00 2001
From: zijunzhao <zijunzhao at google.com>
Date: Thu, 19 Oct 2023 22:23:03 +0000
Subject: [PATCH 1/4] Update stdckdint.h and make it available in pre-C23
 modes.

Update some tests and docs.
---
 clang/docs/ReleaseNotes.rst    | 2 +-
 clang/lib/Headers/stdckdint.h  | 4 ----
 clang/test/C/C2x/n2359.c       | 5 -----
 clang/test/C/C2x/n2683.c       | 1 +
 clang/test/C/C2x/n2683_2.c     | 1 +
 clang/test/Headers/stdckdint.c | 7 +++++--
 6 files changed, 8 insertions(+), 12 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index fc8caf9221b9d29..d0de52a5bf122f4 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -177,7 +177,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. And 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..77290b260ff3bd4 100644
--- a/clang/lib/Headers/stdckdint.h
+++ b/clang/lib/Headers/stdckdint.h
@@ -21,9 +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-
 // precise integer type, or an enumerated type, and they need not be the same.
 
@@ -38,7 +35,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/C/C2x/n2359.c b/clang/test/C/C2x/n2359.c
index dc38bab43c9db8d..0a1b801e505e146 100644
--- a/clang/test/C/C2x/n2359.c
+++ b/clang/test/C/C2x/n2359.c
@@ -33,8 +33,3 @@
 #error "__STDC_VERSION_STDINT_H__ not defined"
 // expected-error at -1 {{"__STDC_VERSION_STDINT_H__ not defined"}}
 #endif
-
-#include <stdckdint.h>
-#ifndef __STDC_VERSION_STDCKDINT_H__
-#error "__STDC_VERSION_STDCKDINT_H__ not defined"
-#endif
diff --git a/clang/test/C/C2x/n2683.c b/clang/test/C/C2x/n2683.c
index 0c666c5fd8782ba..a785d46c063c2cc 100644
--- a/clang/test/C/C2x/n2683.c
+++ b/clang/test/C/C2x/n2683.c
@@ -1,4 +1,5 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 3
+// RUN: %clang_cc1 -triple=x86_64 -verify -ffreestanding -std=c2x %s
 // RUN: %clang_cc1 -triple=x86_64 -verify -ffreestanding -std=c23 %s
 
 /* WG14 N2683: Clang 18
diff --git a/clang/test/C/C2x/n2683_2.c b/clang/test/C/C2x/n2683_2.c
index 247f6de8fe4bfe1..867d6b876cf0d9d 100644
--- a/clang/test/C/C2x/n2683_2.c
+++ b/clang/test/C/C2x/n2683_2.c
@@ -1,4 +1,5 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 3
+// RUN: %clang_cc1 -triple=x86_64 -emit-llvm -o - -std=c2x %s | FileCheck %s
 // RUN: %clang_cc1 -triple=x86_64 -emit-llvm -o - -std=c23 %s | FileCheck %s
 
 #include <stdckdint.h>
diff --git a/clang/test/Headers/stdckdint.c b/clang/test/Headers/stdckdint.c
index 896c740360065b6..7774cecfa7c3317 100644
--- a/clang/test/Headers/stdckdint.c
+++ b/clang/test/Headers/stdckdint.c
@@ -1,12 +1,15 @@
 // 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=c2x %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:

>From 4e2fd920121b15e014a6146c6c6672973bae4443 Mon Sep 17 00:00:00 2001
From: zijunzhao <zijunzhao at google.com>
Date: Thu, 19 Oct 2023 22:23:03 +0000
Subject: [PATCH 2/4] Update stdckdint.h and make it available in pre-C23
 modes.

Update some tests and docs.
---
 clang/docs/ReleaseNotes.rst   | 2 +-
 clang/lib/Headers/stdckdint.h | 4 ++++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index d0de52a5bf122f4..1b1f25ae244ef9f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -177,7 +177,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. And it is also exposed in pre-C23 modes.
+  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 77290b260ff3bd4..35e47b2748094bd 100644
--- a/clang/lib/Headers/stdckdint.h
+++ b/clang/lib/Headers/stdckdint.h
@@ -21,6 +21,10 @@
 
 /* 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
+#endif
+
 // Both A and B shall be any integer type other than "plain" char, bool, a bit-
 // precise integer type, or an enumerated type, and they need not be the same.
 

>From 82d6146dedd89707b7ef6d445e56f14330d45c43 Mon Sep 17 00:00:00 2001
From: zijunzhao <zijunzhao at google.com>
Date: Thu, 19 Oct 2023 22:23:03 +0000
Subject: [PATCH 3/4] Update stdckdint.h and make it available in pre-C23
 modes.

Update some tests and docs.
---
 clang/test/C/C2x/n2359.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/clang/test/C/C2x/n2359.c b/clang/test/C/C2x/n2359.c
index 0a1b801e505e146..dc38bab43c9db8d 100644
--- a/clang/test/C/C2x/n2359.c
+++ b/clang/test/C/C2x/n2359.c
@@ -33,3 +33,8 @@
 #error "__STDC_VERSION_STDINT_H__ not defined"
 // expected-error at -1 {{"__STDC_VERSION_STDINT_H__ not defined"}}
 #endif
+
+#include <stdckdint.h>
+#ifndef __STDC_VERSION_STDCKDINT_H__
+#error "__STDC_VERSION_STDCKDINT_H__ not defined"
+#endif

>From dd179f4fe1d05de2c8543cf2325d88ad26ec2b28 Mon Sep 17 00:00:00 2001
From: zijunzhao <zijunzhao at google.com>
Date: Mon, 23 Oct 2023 18:38:21 +0000
Subject: [PATCH 4/4] Update code

---
 clang/lib/Headers/stdckdint.h  | 2 --
 clang/test/C/C2x/n2683.c       | 1 -
 clang/test/C/C2x/n2683_2.c     | 1 -
 clang/test/Headers/stdckdint.c | 1 -
 4 files changed, 5 deletions(-)

diff --git a/clang/lib/Headers/stdckdint.h b/clang/lib/Headers/stdckdint.h
index 35e47b2748094bd..20bc34ffb30235c 100644
--- a/clang/lib/Headers/stdckdint.h
+++ b/clang/lib/Headers/stdckdint.h
@@ -21,9 +21,7 @@
 
 /* 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
-#endif
 
 // Both A and B shall be any integer type other than "plain" char, bool, a bit-
 // precise integer type, or an enumerated type, and they need not be the same.
diff --git a/clang/test/C/C2x/n2683.c b/clang/test/C/C2x/n2683.c
index a785d46c063c2cc..0c666c5fd8782ba 100644
--- a/clang/test/C/C2x/n2683.c
+++ b/clang/test/C/C2x/n2683.c
@@ -1,5 +1,4 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 3
-// RUN: %clang_cc1 -triple=x86_64 -verify -ffreestanding -std=c2x %s
 // RUN: %clang_cc1 -triple=x86_64 -verify -ffreestanding -std=c23 %s
 
 /* WG14 N2683: Clang 18
diff --git a/clang/test/C/C2x/n2683_2.c b/clang/test/C/C2x/n2683_2.c
index 867d6b876cf0d9d..247f6de8fe4bfe1 100644
--- a/clang/test/C/C2x/n2683_2.c
+++ b/clang/test/C/C2x/n2683_2.c
@@ -1,5 +1,4 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 3
-// RUN: %clang_cc1 -triple=x86_64 -emit-llvm -o - -std=c2x %s | FileCheck %s
 // RUN: %clang_cc1 -triple=x86_64 -emit-llvm -o - -std=c23 %s | FileCheck %s
 
 #include <stdckdint.h>
diff --git a/clang/test/Headers/stdckdint.c b/clang/test/Headers/stdckdint.c
index 7774cecfa7c3317..6b6d74a89d4c111 100644
--- a/clang/test/Headers/stdckdint.c
+++ b/clang/test/Headers/stdckdint.c
@@ -2,7 +2,6 @@
 // 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=c2x %s -o - | FileCheck %s
 // RUN: %clang_cc1 -triple=x86_64 -emit-llvm -verify -std=c23 %s -o - | FileCheck %s
 
 // expected-no-diagnostics



More information about the Mlir-commits mailing list