[libc-commits] [libc] [libc] newheadergen: added assert.yaml (PR #98826)

via libc-commits libc-commits at lists.llvm.org
Sun Jul 14 11:10:54 PDT 2024


https://github.com/aaryanshukla created https://github.com/llvm/llvm-project/pull/98826

- removed assert macro definitions in api.td
- included macro definitions in assert.h.def
- added assert.yaml


>From f0be4e2bc4a53696372198280551f7259f719272 Mon Sep 17 00:00:00 2001
From: Aaryan Shukla <aaryanshukla at google.com>
Date: Sun, 14 Jul 2024 18:09:32 +0000
Subject: [PATCH] [libc] newheadergen: added assert.yaml

- removed assert macro definitions in api.td
- included macro definitions in assert.h.def
- added assert.yaml
---
 libc/config/baremetal/api.td    | 35 --------------------------------
 libc/config/gpu/api.td          | 29 --------------------------
 libc/config/linux/api.td        | 36 ---------------------------------
 libc/include/assert.h.def       | 20 ++++++++++++++++++
 libc/newhdrgen/yaml/assert.yaml | 16 +++++++++++++++
 5 files changed, 36 insertions(+), 100 deletions(-)
 create mode 100644 libc/newhdrgen/yaml/assert.yaml

diff --git a/libc/config/baremetal/api.td b/libc/config/baremetal/api.td
index a6547d843c85e..7421d86fabeb0 100644
--- a/libc/config/baremetal/api.td
+++ b/libc/config/baremetal/api.td
@@ -5,41 +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 21ddbb95b70c9..995ff31c4ac9e 100644
--- a/libc/config/gpu/api.td
+++ b/libc/config/gpu/api.td
@@ -7,35 +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 60e9b70f0d8a4..a10dec06e2452 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 15077e53e2ca4..9c924c7f58545 100644
--- a/libc/include/assert.h.def
+++ b/libc/include/assert.h.def
@@ -12,4 +12,24 @@
 // This file may be usefully included multiple times to change assert()'s
 // definition based on NDEBUG.
 
+
+#undef assert
+#ifdef NDEBUG
+#define assert(e) (void)0
+#else
+
+#ifndef __cplusplus
+#undef static_assert
+#define static_assert _Static_assert
+#endif
+
+#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..9ad0f0628274e
--- /dev/null
+++ b/libc/newhdrgen/yaml/assert.yaml
@@ -0,0 +1,16 @@
+header: assert.h
+macros: []
+types: []
+enums: []
+objects: []
+functions:
+  - name: __assert_fail 
+    standards:
+      - llvm_libc_ext
+    return_type: _Noreturn void
+    arguments:
+      - type: const char *
+      - type: const char *
+      - type: unsigned
+      - type: const char *
+    guard: __cplusplus



More information about the libc-commits mailing list