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

via libc-commits libc-commits at lists.llvm.org
Mon Jul 8 15:41:06 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: None (aaryanshukla)

<details>
<summary>Changes</summary>

- 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.


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


2 Files Affected:

- (modified) libc/include/assert.h.def (+17) 
- (added) libc/newhdrgen/yaml/assert.yaml (+15) 


``````````diff
diff --git a/libc/include/assert.h.def b/libc/include/assert.h.def
index 15077e53e2ca48..d5ae14a1cd8101 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 00000000000000..85de6bc867b224
--- /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

``````````

</details>


https://github.com/llvm/llvm-project/pull/98092


More information about the libc-commits mailing list