Skip to content

Conversation

bassiounix
Copy link
Contributor

@bassiounix bassiounix commented Oct 12, 2025

RFC https://discourse.llvm.org/t/rfc-bounds-checking-interfaces-for-llvm-libc/87685

Add internal support macros required by Annex K interface in LLVM libc.

Copy link
Contributor Author

bassiounix commented Oct 12, 2025

@llvmbot
Copy link
Member

llvmbot commented Oct 12, 2025

@llvm/pr-subscribers-libc

Author: Muhammad Bassiouni (bassiounix)

Changes

RFC https://discourse.llvm.org/t/rfc-bounds-checking-interfaces-for-llvm-libc/87685

Add internal support macros required by Annex K interface in LLVM libc.


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

2 Files Affected:

  • (modified) libc/include/llvm-libc-macros/CMakeLists.txt (+6)
  • (added) libc/include/llvm-libc-macros/annex-k-macros.h (+26)
diff --git a/libc/include/llvm-libc-macros/CMakeLists.txt b/libc/include/llvm-libc-macros/CMakeLists.txt
index 76c03d913ee12..f41da94e1d726 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(
+  annex_k_macros
+  HDR
+    annex-k-macros.h
+)
+
 add_macro_header(
   assert_macros
   HDR
diff --git a/libc/include/llvm-libc-macros/annex-k-macros.h b/libc/include/llvm-libc-macros/annex-k-macros.h
new file mode 100644
index 0000000000000..c3f845cd77574
--- /dev/null
+++ b/libc/include/llvm-libc-macros/annex-k-macros.h
@@ -0,0 +1,26 @@
+//===-- Definition of macros to be used with Annex K 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_INCLUDE_LLVM_LIBC_MACROS_ANNEX_K_MACROS_H
+#define LLVM_LIBC_INCLUDE_LLVM_LIBC_MACROS_ANNEX_K_MACROS_H
+
+#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) ||              \
+    (defined(__cplusplus) && __cplusplus >= 201703L)
+
+// TODO(bassiounix): Who should def this macro (clang vs libc)? Where?
+#define __STDC_LIB_EXT1__ 201112L
+
+#if defined(__STDC_WANT_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__ == 1
+
+#define LIBC_HAS_ANNEX_K
+
+#endif // defined(__STDC_WANT_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__ == 1
+
+#endif // (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) ||
+       // (defined(__cplusplus) && __cplusplus >= 201703L)
+#endif // LLVM_LIBC_INCLUDE_LLVM_LIBC_MACROS_ANNEX_K_MACROS_H

@bassiounix bassiounix force-pushed the users/bassiounix/spr/10-12-_libc_annex_k_add_errno_t branch from d526d47 to b00886e Compare October 13, 2025 18:15
@bassiounix bassiounix force-pushed the users/bassiounix/spr/10-12-_libc_annex_k_add_annex_k_support_macros branch from b9ff3d0 to f71d62a Compare October 13, 2025 18:15
@bassiounix bassiounix force-pushed the users/bassiounix/spr/10-12-_libc_annex_k_add_annex_k_support_macros branch from f71d62a to 6230cba Compare October 13, 2025 21:52
Comment on lines +15 to +16
// TODO(bassiounix): Who should def this macro (clang vs libc)? Where?
#define __STDC_LIB_EXT1__ 201112L
Copy link
Contributor

Choose a reason for hiding this comment

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

Per C23/N3220 6.10.10 Predefined macro names, __STDC_LIB_EXT1__ is (conditionally) predefined. So perhaps Clang should define it while libc should not.

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.

3 participants