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

Conversation

ZijunZhaoCCK
Copy link
Contributor

@ZijunZhaoCCK ZijunZhaoCCK commented Oct 19, 2023

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

@ZijunZhaoCCK ZijunZhaoCCK marked this pull request as ready for review October 19, 2023 22:27
@llvmbot llvmbot added clang Clang issues not falling into any other category backend:X86 clang:headers Headers provided by Clang, e.g. for intrinsics labels Oct 19, 2023
@llvmbot
Copy link
Member

llvmbot commented Oct 19, 2023

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-backend-x86

Author: None (ZijunZhaoCCK)

Changes

Update some tests and docs.


Full diff: https://github.com/llvm/llvm-project/pull/69649.diff

6 Files Affected:

  • (modified) clang/docs/ReleaseNotes.rst (+1-1)
  • (modified) clang/lib/Headers/stdckdint.h (-4)
  • (modified) clang/test/C/C2x/n2359.c (-5)
  • (modified) clang/test/C/C2x/n2683.c (+1)
  • (modified) clang/test/C/C2x/n2683_2.c (+1)
  • (modified) clang/test/Headers/stdckdint.c (+5-2)
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@-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:

Copy link
Collaborator

@AaronBallman AaronBallman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you!

@AaronBallman
Copy link
Collaborator

The precommit CI failures are unrelated to the changes in this patch. However, when landing the patch, please be sure to update the commit message.

@ZijunZhaoCCK ZijunZhaoCCK merged commit 7e34ee5 into llvm:main Oct 25, 2023
@ZijunZhaoCCK ZijunZhaoCCK deleted the stdckdint branch January 9, 2024 22:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:X86 clang:headers Headers provided by Clang, e.g. for intrinsics clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants