Skip to content

[libc][assert] define __STDC_VERSION_ASSERT_H__ #87592

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 24, 2024

Conversation

aniplcc
Copy link
Contributor

@aniplcc aniplcc commented Apr 4, 2024

Fixes #87561

@llvmbot llvmbot added the libc label Apr 4, 2024
@llvmbot
Copy link
Member

llvmbot commented Apr 4, 2024

@llvm/pr-subscribers-libc

Author: aniplcc (aniplcc)

Changes

Fixes #87561


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

5 Files Affected:

  • (modified) libc/include/assert.h.def (+7-1)
  • (modified) libc/include/llvm-libc-macros/CMakeLists.txt (+6)
  • (added) libc/include/llvm-libc-macros/assert-macros.h (+14)
  • (modified) libc/test/include/CMakeLists.txt (+10)
  • (added) libc/test/include/assert_test.cpp (+15)
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/CMakeLists.txt b/libc/include/llvm-libc-macros/CMakeLists.txt
index 635ccadfb49e7d..3b1b9e173d6816 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
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/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
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);
+}

Copy link
Member

@nickdesaulniers nickdesaulniers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove the header guard, but let's see what @michaelrj-google thinks about the thread I started related to where/how we define __STDC_VERSION_ASSERT_H__.

Copy link
Contributor

@michaelrj-google michaelrj-google left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! Sorry it took me so long to get back to you, the patch looks good overall with one nit: you need to move the #include up to the top with the other #include.

@aniplcc
Copy link
Contributor Author

aniplcc commented Apr 24, 2024

Updated

Copy link
Contributor

@michaelrj-google michaelrj-google left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, feel free to ping me if you need me to merge this for you.

@aniplcc
Copy link
Contributor Author

aniplcc commented Apr 24, 2024

@michaelrj-google you can merge this, thanks!

@michaelrj-google michaelrj-google merged commit 11bd19a into llvm:main Apr 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[libc][assert] Define __STDC_VERSION_ASSERT_H__
4 participants