[libc-commits] [libc] [libc][assert] define __STDC_VERSION_ASSERT_H__ (PR #87592)

via libc-commits libc-commits at lists.llvm.org
Tue Apr 23 20:01:41 PDT 2024


https://github.com/aniplcc updated https://github.com/llvm/llvm-project/pull/87592

>From 6802dcc899dc48f0c632292be80c8e7918526318 Mon Sep 17 00:00:00 2001
From: aniplcc <aniplccode at gmail.com>
Date: Thu, 4 Apr 2024 06:52:11 +0530
Subject: [PATCH 1/6] [libc][assert] define __STDC_VERSION_ASSERT_H__

---
 libc/include/assert.h.def                     |  8 +++++++-
 libc/include/llvm-libc-macros/assert-macros.h | 14 ++++++++++++++
 libc/test/include/assert_test.cpp             | 15 +++++++++++++++
 3 files changed, 36 insertions(+), 1 deletion(-)
 create mode 100644 libc/include/llvm-libc-macros/assert-macros.h
 create mode 100644 libc/test/include/assert_test.cpp

diff --git a/libc/include/assert.h.def b/libc/include/assert.h.def
index e006133a76542a..65f476f6886d9a 100644
--- a/libc/include/assert.h.def
+++ b/libc/include/assert.h.def
@@ -1,14 +1,20 @@
 //===-- C standard library header assert.h --------------------------------===//
-//
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
 
+#ifndef LLVM_LIBC_ASSERT_H
+#define LLVM_LIBC_ASSERT_H
+
 #include "__llvm-libc-common.h"
 
 // This file may be usefully included multiple times to change assert()'s
 // definition based on NDEBUG.
 
 %%public_api()
+
+#include "llvm-libc-macros/assert-macros.h"
+
+#endif // LLVM_LIBC_ASSERT_H
diff --git a/libc/include/llvm-libc-macros/assert-macros.h b/libc/include/llvm-libc-macros/assert-macros.h
new file mode 100644
index 00000000000000..44e14543d8562e
--- /dev/null
+++ b/libc/include/llvm-libc-macros/assert-macros.h
@@ -0,0 +1,14 @@
+//===-- Definition of macros to be used with assert functions -------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef __LLVM_LIBC_MACROS_ASSERT_MACROS_H
+#define __LLVM_LIBC_MACROS_ASSERT_MACROS_H
+
+#define __STDC_VERSION_ASSERT_H__ 202311L
+
+#endif // __LLVM_LIBC_MACROS_ASSERT_MACROS_H
diff --git a/libc/test/include/assert_test.cpp b/libc/test/include/assert_test.cpp
new file mode 100644
index 00000000000000..78709bbcdd5941
--- /dev/null
+++ b/libc/test/include/assert_test.cpp
@@ -0,0 +1,15 @@
+//===-- Unittests for assert ----------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDSList-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "include/llvm-libc-macros/assert-macros.h"
+#include "test/UnitTest/Test.h"
+
+TEST(LlvmLibcAssertTest, VersionMacro) {
+  // 7.2p3 an integer constant expression with a value equivalent to 202311L.
+  EXPECT_EQ(__STDC_VERSION_ASSERT_H__, 202311L);
+}

>From ffd999b1998f85270d17901db2ef367480cd7807 Mon Sep 17 00:00:00 2001
From: aniplcc <aniplccode at gmail.com>
Date: Thu, 4 Apr 2024 07:14:16 +0530
Subject: [PATCH 2/6] update cmake

---
 libc/test/include/CMakeLists.txt | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/libc/test/include/CMakeLists.txt b/libc/test/include/CMakeLists.txt
index 8d8dff53169f6a..03c31855e352ba 100644
--- a/libc/test/include/CMakeLists.txt
+++ b/libc/test/include/CMakeLists.txt
@@ -1,5 +1,15 @@
 add_custom_target(libc_include_tests)
 
+add_libc_test(
+  assert_test
+  SUITE
+    libc_include_tests
+  SRCS
+    assert_test.cpp
+  DEPENDS
+    libc.include.llvm-libc-macros.assert_macros
+)
+
 add_libc_test(
   sys_queue_test
   SUITE

>From 92bf1201340c04b82e48a26aadf2c31804650856 Mon Sep 17 00:00:00 2001
From: aniplcc <aniplccode at gmail.com>
Date: Thu, 4 Apr 2024 07:41:02 +0530
Subject: [PATCH 3/6] update cmake

---
 libc/include/llvm-libc-macros/CMakeLists.txt | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/libc/include/llvm-libc-macros/CMakeLists.txt b/libc/include/llvm-libc-macros/CMakeLists.txt
index 382cb8ee417e16..68ba110aec80f1 100644
--- a/libc/include/llvm-libc-macros/CMakeLists.txt
+++ b/libc/include/llvm-libc-macros/CMakeLists.txt
@@ -31,6 +31,12 @@ if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
   add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
 endif()
 
+add_macro_header(
+  assert_macros
+  HDR
+    assert-macros.h
+)
+
 add_macro_header(
   generic_error_number_macros
   HDR

>From 77c5a81c46d911819df56a87efbd463b9b284758 Mon Sep 17 00:00:00 2001
From: aniplcc <aniplccode at gmail.com>
Date: Thu, 4 Apr 2024 07:45:14 +0530
Subject: [PATCH 4/6] Update assert.h.def

---
 libc/include/assert.h.def | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libc/include/assert.h.def b/libc/include/assert.h.def
index 65f476f6886d9a..03b53e7d75780f 100644
--- a/libc/include/assert.h.def
+++ b/libc/include/assert.h.def
@@ -1,4 +1,5 @@
 //===-- C standard library header assert.h --------------------------------===//
+//
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

>From f8609bf93a392be53cdceee40adda2322bb3522a Mon Sep 17 00:00:00 2001
From: aniplcc <aniplccode at gmail.com>
Date: Thu, 4 Apr 2024 23:48:29 +0530
Subject: [PATCH 5/6] Update assert.h.def

---
 libc/include/assert.h.def | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/libc/include/assert.h.def b/libc/include/assert.h.def
index 03b53e7d75780f..0fb4142076b495 100644
--- a/libc/include/assert.h.def
+++ b/libc/include/assert.h.def
@@ -6,9 +6,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_LIBC_ASSERT_H
-#define LLVM_LIBC_ASSERT_H
-
 #include "__llvm-libc-common.h"
 
 // This file may be usefully included multiple times to change assert()'s
@@ -17,5 +14,3 @@
 %%public_api()
 
 #include "llvm-libc-macros/assert-macros.h"
-
-#endif // LLVM_LIBC_ASSERT_H

>From 377918716c5590acbc3d4428b3044b466b823a6f Mon Sep 17 00:00:00 2001
From: aniplcc <aniplccode at gmail.com>
Date: Wed, 24 Apr 2024 08:30:57 +0530
Subject: [PATCH 6/6] Update assert.h.def

---
 libc/include/assert.h.def | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/libc/include/assert.h.def b/libc/include/assert.h.def
index 0fb4142076b495..15077e53e2ca48 100644
--- a/libc/include/assert.h.def
+++ b/libc/include/assert.h.def
@@ -7,10 +7,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "__llvm-libc-common.h"
+#include "llvm-libc-macros/assert-macros.h"
 
 // This file may be usefully included multiple times to change assert()'s
 // definition based on NDEBUG.
 
 %%public_api()
-
-#include "llvm-libc-macros/assert-macros.h"



More information about the libc-commits mailing list