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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am commenting this define for now. The standard specifies that any implementation that adheres to the standard should conditionally define __STDC_LIB_EXT1__.
We haven't fully implemented Annex K yet, so no need to introduce it now.

@bassiounix bassiounix force-pushed the users/bassiounix/spr/10-12-_libc_annex_k_add_annex_k_support_macros branch from 6230cba to 5215358 Compare October 16, 2025 21:54
@bassiounix bassiounix force-pushed the users/bassiounix/spr/10-12-_libc_annex_k_add_errno_t branch from b841bdd to 0d3f72e Compare October 16, 2025 21:54
@bassiounix bassiounix force-pushed the users/bassiounix/spr/10-12-_libc_annex_k_add_annex_k_support_macros branch from 5215358 to 11870cc Compare October 16, 2025 22:17
@bassiounix bassiounix changed the base branch from users/bassiounix/spr/10-12-_libc_annex_k_add_errno_t to main October 16, 2025 22:39
@bassiounix bassiounix changed the base branch from main to users/bassiounix/spr/10-12-_libc_annex_k_add_errno_t October 16, 2025 22:46
@bassiounix bassiounix changed the base branch from users/bassiounix/spr/10-12-_libc_annex_k_add_errno_t to main October 16, 2025 23:00
@bassiounix bassiounix force-pushed the users/bassiounix/spr/10-12-_libc_annex_k_add_annex_k_support_macros branch from 11870cc to 2a3f07f Compare October 16, 2025 23:01
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.

Looks good to me once the question of if the compiler or the library should define the macro is resolved.

@bassiounix
Copy link
Contributor Author

Looks good to me once the question of if the compiler or the library should define the macro is resolved.

I am commenting this define for now. The standard specifies that any implementation that adheres to the standard should conditionally define __STDC_LIB_EXT1__.
We haven't fully implemented Annex K yet, so no need to introduce it now.

@bassiounix bassiounix force-pushed the users/bassiounix/spr/10-12-_libc_annex_k_add_annex_k_support_macros branch from b16ae89 to dff862b Compare October 18, 2025 15:02
Copy link
Contributor Author

bassiounix commented Oct 22, 2025

Merge activity

  • Oct 22, 6:23 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Oct 22, 6:25 PM UTC: @bassiounix merged this pull request with Graphite.

@bassiounix bassiounix merged commit 58d4f18 into main Oct 22, 2025
20 checks passed
@bassiounix bassiounix deleted the users/bassiounix/spr/10-12-_libc_annex_k_add_annex_k_support_macros branch October 22, 2025 18:25
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.

4 participants