[libc-commits] [libc] [libc] assert.h modifications for newhdrgen (PR #98092)
via libc-commits
libc-commits at lists.llvm.org
Mon Jul 8 19:22:27 PDT 2024
https://github.com/aaryanshukla updated https://github.com/llvm/llvm-project/pull/98092
>From bea73e66cab780c8b449d80b86a3b0fb3975e367 Mon Sep 17 00:00:00 2001
From: Aaryan Shukla <aaryanshukla at google.com>
Date: Mon, 8 Jul 2024 22:37:32 +0000
Subject: [PATCH 1/3] [libc] assert.h modifications for newhdrgen
- currently assert.h has a lot of code that does not have a position in
our yaml files. Other files like errno.h and syscall.h have this code
in their respective .h.def files. We want to add that feature to
assert.h by changing assert.h.def.
---
libc/include/assert.h.def | 17 +++++++++++++++++
libc/newhdrgen/yaml/assert.yaml | 15 +++++++++++++++
2 files changed, 32 insertions(+)
create mode 100644 libc/newhdrgen/yaml/assert.yaml
diff --git a/libc/include/assert.h.def b/libc/include/assert.h.def
index 15077e53e2ca4..d5ae14a1cd810 100644
--- a/libc/include/assert.h.def
+++ b/libc/include/assert.h.def
@@ -12,4 +12,21 @@
// This file may be usefully included multiple times to change assert()'s
// definition based on NDEBUG.
+#ifndef __cplusplus
+#undef static_assert
+#define static_assert _Static_assert
+#endif
+
+#undef assert
+#ifdef NDEBUG
+#define assert(e) (void)0
+#else
+#ifdef __cplusplus
+extern "C"
+#endif
+_Noreturn void __assert_fail(const char *, const char *, unsigned, const char *) __NOEXCEPT;
+#define assert(e) \
+ ((e) ? (void)0 : __assert_fail(#e, __FILE__, __LINE__, __PRETTY_FUNCTION__))
+#endif
+
%%public_api()
diff --git a/libc/newhdrgen/yaml/assert.yaml b/libc/newhdrgen/yaml/assert.yaml
new file mode 100644
index 0000000000000..85de6bc867b22
--- /dev/null
+++ b/libc/newhdrgen/yaml/assert.yaml
@@ -0,0 +1,15 @@
+header: assert.h
+macros: []
+types: []
+enums: []
+objects: []
+functions:
+ - name: __assert_fail
+ - llvm_libc_ext
+ return_type: _Noreturn void
+ arguments:
+ - type: const char *
+ - type: const char *
+ - type: unsigned
+ - type: const char *
+ guard: __cplusplus
\ No newline at end of file
>From 9796467a786775b8d6a9297c9dc9e6f6bf8ea96a Mon Sep 17 00:00:00 2001
From: Aaryan Shukla <aaryanshukla at google.com>
Date: Mon, 8 Jul 2024 22:54:50 +0000
Subject: [PATCH 2/3] added newline
---
libc/newhdrgen/yaml/assert.yaml | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/libc/newhdrgen/yaml/assert.yaml b/libc/newhdrgen/yaml/assert.yaml
index 85de6bc867b22..d1db8e9262208 100644
--- a/libc/newhdrgen/yaml/assert.yaml
+++ b/libc/newhdrgen/yaml/assert.yaml
@@ -12,4 +12,5 @@ functions:
- type: const char *
- type: unsigned
- type: const char *
- guard: __cplusplus
\ No newline at end of file
+ guard: __cplusplus
+
\ No newline at end of file
>From 2753d0a5dc714c40cea46555527cfb266c14e3d6 Mon Sep 17 00:00:00 2001
From: Aaryan Shukla <aaryanshukla at google.com>
Date: Tue, 9 Jul 2024 02:21:20 +0000
Subject: [PATCH 3/3] removed assert info from api.td
- adjusted assert.h.def based on common.h
- fixed assert.yaml
---
libc/config/baremetal/api.td | 36 ---------------------------------
libc/config/gpu/api.td | 30 ---------------------------
libc/config/linux/api.td | 36 ---------------------------------
libc/include/assert.h.def | 8 +-------
libc/newhdrgen/yaml/assert.yaml | 1 +
5 files changed, 2 insertions(+), 109 deletions(-)
diff --git a/libc/config/baremetal/api.td b/libc/config/baremetal/api.td
index a6547d843c85e..08d62a0f58b89 100644
--- a/libc/config/baremetal/api.td
+++ b/libc/config/baremetal/api.td
@@ -5,42 +5,6 @@ include "spec/stdc_ext.td"
include "spec/bsd_ext.td"
include "spec/llvm_libc_stdfix_ext.td"
-def AssertMacro : MacroDef<"assert"> {
- let Defn = [{
- #undef assert
-
- #ifdef NDEBUG
- #define assert(e) (void)0
- #else
-
- #ifdef __cplusplus
- extern "C"
- #endif
- _Noreturn void __assert_fail(const char *, const char *, unsigned, const char *) __NOEXCEPT;
-
- #define assert(e) \
- ((e) ? (void)0 : __assert_fail(#e, __FILE__, __LINE__, __PRETTY_FUNCTION__))
-
- #endif
- }];
-}
-
-def StaticAssertMacro : MacroDef<"static_assert"> {
- let Defn = [{
- #ifndef __cplusplus
- #undef static_assert
- #define static_assert _Static_assert
- #endif
- }];
-}
-
-def AssertAPI : PublicAPI<"assert.h"> {
- let Macros = [
- AssertMacro,
- StaticAssertMacro,
- ];
-}
-
def CTypeAPI : PublicAPI<"ctype.h"> {
}
diff --git a/libc/config/gpu/api.td b/libc/config/gpu/api.td
index 523ad49ffa3fd..b7b70007cc38d 100644
--- a/libc/config/gpu/api.td
+++ b/libc/config/gpu/api.td
@@ -7,36 +7,6 @@ include "spec/gnu_ext.td"
include "spec/stdc_ext.td"
include "spec/llvm_libc_ext.td"
-def AssertMacro : MacroDef<"assert"> {
- let Defn = [{
- #undef assert
-
- #ifdef NDEBUG
- #define assert(e) (void)0
- #else
-
- #define assert(e) \
- ((e) ? (void)0 : __assert_fail(#e, __FILE__, __LINE__, __PRETTY_FUNCTION__))
- #endif
- }];
-}
-
-def StaticAssertMacro : MacroDef<"static_assert"> {
- let Defn = [{
- #ifndef __cplusplus
- #undef static_assert
- #define static_assert _Static_assert
- #endif
- }];
-}
-
-def AssertAPI : PublicAPI<"assert.h"> {
- let Macros = [
- AssertMacro,
- StaticAssertMacro,
- ];
-}
-
def StringAPI : PublicAPI<"string.h"> {
let Types = ["size_t"];
}
diff --git a/libc/config/linux/api.td b/libc/config/linux/api.td
index eb0090c80b0da..562ece9f7c5db 100644
--- a/libc/config/linux/api.td
+++ b/libc/config/linux/api.td
@@ -9,42 +9,6 @@ include "spec/stdc_ext.td"
include "spec/llvm_libc_ext.td"
include "spec/llvm_libc_stdfix_ext.td"
-def AssertMacro : MacroDef<"assert"> {
- let Defn = [{
- #undef assert
-
- #ifdef NDEBUG
- #define assert(e) (void)0
- #else
-
- #ifdef __cplusplus
- extern "C"
- #endif
- _Noreturn void __assert_fail(const char *, const char *, unsigned, const char *) __NOEXCEPT;
-
- #define assert(e) \
- ((e) ? (void)0 : __assert_fail(#e, __FILE__, __LINE__, __PRETTY_FUNCTION__))
-
- #endif
- }];
-}
-
-def StaticAssertMacro : MacroDef<"static_assert"> {
- let Defn = [{
- #ifndef __cplusplus
- #undef static_assert
- #define static_assert _Static_assert
- #endif
- }];
-}
-
-def AssertAPI : PublicAPI<"assert.h"> {
- let Macros = [
- AssertMacro,
- StaticAssertMacro,
- ];
-}
-
def CTypeAPI : PublicAPI<"ctype.h"> {
}
diff --git a/libc/include/assert.h.def b/libc/include/assert.h.def
index d5ae14a1cd810..4d06bf74f7b04 100644
--- a/libc/include/assert.h.def
+++ b/libc/include/assert.h.def
@@ -12,18 +12,12 @@
// This file may be usefully included multiple times to change assert()'s
// definition based on NDEBUG.
-#ifndef __cplusplus
-#undef static_assert
-#define static_assert _Static_assert
-#endif
#undef assert
#ifdef NDEBUG
#define assert(e) (void)0
#else
-#ifdef __cplusplus
-extern "C"
-#endif
+
_Noreturn void __assert_fail(const char *, const char *, unsigned, const char *) __NOEXCEPT;
#define assert(e) \
((e) ? (void)0 : __assert_fail(#e, __FILE__, __LINE__, __PRETTY_FUNCTION__))
diff --git a/libc/newhdrgen/yaml/assert.yaml b/libc/newhdrgen/yaml/assert.yaml
index d1db8e9262208..6281b23a69fad 100644
--- a/libc/newhdrgen/yaml/assert.yaml
+++ b/libc/newhdrgen/yaml/assert.yaml
@@ -5,6 +5,7 @@ enums: []
objects: []
functions:
- name: __assert_fail
+ standards:
- llvm_libc_ext
return_type: _Noreturn void
arguments:
More information about the libc-commits
mailing list