[libc-commits] [libc] [libc] assert.h modifications for newhdrgen (PR #98092)

via libc-commits libc-commits at lists.llvm.org
Mon Jul 8 15:55:15 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/2] [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/2] 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



More information about the libc-commits mailing list