Skip to content

Conversation

bassiounix
Copy link
Contributor

@bassiounix bassiounix commented Oct 13, 2025

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

Add constraint_handler_t type required by Annex K interface in LLVM libc.

Copy link
Contributor Author

bassiounix commented Oct 13, 2025

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@llvmbot
Copy link
Member

llvmbot commented Oct 13, 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 constraint_handler_t type required by Annex K interface in LLVM libc.


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

5 Files Affected:

  • (modified) libc/hdr/types/CMakeLists.txt (+9)
  • (added) libc/hdr/types/constraint_handler_t.h (+18)
  • (modified) libc/include/llvm-libc-types/CMakeLists.txt (+2)
  • (added) libc/include/llvm-libc-types/constraint_handler_t.h (+21)
  • (modified) libc/include/stdlib.yaml (+1)
diff --git a/libc/hdr/types/CMakeLists.txt b/libc/hdr/types/CMakeLists.txt
index 1ef1a2bee6f80..4129d35adfb9d 100644
--- a/libc/hdr/types/CMakeLists.txt
+++ b/libc/hdr/types/CMakeLists.txt
@@ -170,6 +170,15 @@ add_proxy_header_library(
     libc.include.fcntl
 )
 
+add_proxy_header_library(
+  constraint_handler_t
+  HDRS
+    constraint_handler_t.h
+  FULL_BUILD_DEPENDS
+    libc.include.llvm-libc-types.constraint_handler_t
+    libc.include.stdlib
+)
+
 add_proxy_header_library(
   errno_t
   HDRS
diff --git a/libc/hdr/types/constraint_handler_t.h b/libc/hdr/types/constraint_handler_t.h
new file mode 100644
index 0000000000000..ca7798b84228e
--- /dev/null
+++ b/libc/hdr/types/constraint_handler_t.h
@@ -0,0 +1,18 @@
+//===-- Proxy for constraint_handler_t ------------------------------------===//
+//
+// 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_HDR_TYPES_CONSTRAINT_HANDLER_T_H
+#define LLVM_LIBC_HDR_TYPES_CONSTRAINT_HANDLER_T_H
+
+#define LIBC_HAS_ANNEX_K
+
+#include "include/llvm-libc-types/constraint_handler_t.h"
+
+#undef LIBC_HAS_ANNEX_K
+
+#endif // LLVM_LIBC_HDR_TYPES_CONSTRAINT_HANDLER_T_H
diff --git a/libc/include/llvm-libc-types/CMakeLists.txt b/libc/include/llvm-libc-types/CMakeLists.txt
index 8e22baa8dfba1..fa9768a0066c5 100644
--- a/libc/include/llvm-libc-types/CMakeLists.txt
+++ b/libc/include/llvm-libc-types/CMakeLists.txt
@@ -299,3 +299,5 @@ add_header(EFI_SYSTEM_TABLE
 )
 
 add_header(errno_t HDR errno_t.h)
+
+add_header(constraint_handler_t HDR constraint_handler_t.h DEPENDS .errno_t)
diff --git a/libc/include/llvm-libc-types/constraint_handler_t.h b/libc/include/llvm-libc-types/constraint_handler_t.h
new file mode 100644
index 0000000000000..efd21296cd399
--- /dev/null
+++ b/libc/include/llvm-libc-types/constraint_handler_t.h
@@ -0,0 +1,21 @@
+//===-- Definition of type constraint_handler_t ---------------------------===//
+//
+// 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_TYPES_CONSTRAINT_HANDLER_T_H
+#define LLVM_LIBC_INCLUDE_LLVM_LIBC_TYPES_CONSTRAINT_HANDLER_T_H
+
+#include "errno_t.h"
+
+#ifdef LIBC_HAS_ANNEX_K
+
+typedef void (*constraint_handler_t)(const char *__restrict, void *__restrict,
+                                     errno_t);
+
+#endif // LIBC_HAS_ANNEX_K
+
+#endif // LLVM_LIBC_INCLUDE_LLVM_LIBC_TYPES_CONSTRAINT_HANDLER_T_H
diff --git a/libc/include/stdlib.yaml b/libc/include/stdlib.yaml
index 3b2ff13c684b1..29fd6bc3a1e75 100644
--- a/libc/include/stdlib.yaml
+++ b/libc/include/stdlib.yaml
@@ -12,6 +12,7 @@ types:
   - type_name: __qsortcompare_t
   - type_name: __qsortrcompare_t
   - type_name: __search_compare_t
+  - type_name: constraint_handler_t
   - type_name: div_t
   - type_name: ldiv_t
   - type_name: lldiv_t

@bassiounix bassiounix force-pushed the users/bassiounix/spr/10-13-_libc_annex_k_add_constraint_handler_t branch 2 times, most recently from d73fce3 to 2fff83c Compare October 13, 2025 21:52
@bassiounix bassiounix force-pushed the users/bassiounix/spr/10-13-_libc_annex_k_add_rsize_t branch from 9f0d7dd to 5383561 Compare October 13, 2025 21:52
@bassiounix bassiounix force-pushed the users/bassiounix/spr/10-13-_libc_annex_k_add_constraint_handler_t branch from 581009d to e4f6c9c Compare October 14, 2025 02:14
@bassiounix bassiounix force-pushed the users/bassiounix/spr/10-13-_libc_annex_k_add_rsize_t branch from 5383561 to c74da0b Compare October 16, 2025 21:54
@bassiounix bassiounix force-pushed the users/bassiounix/spr/10-13-_libc_annex_k_add_constraint_handler_t branch from e4f6c9c to 4490790 Compare October 16, 2025 21:54
@bassiounix bassiounix force-pushed the users/bassiounix/spr/10-13-_libc_annex_k_add_rsize_t branch from c74da0b to aa63b69 Compare October 16, 2025 22:17
@bassiounix bassiounix force-pushed the users/bassiounix/spr/10-13-_libc_annex_k_add_constraint_handler_t branch 2 times, most recently from 3ce1678 to 49c7417 Compare October 16, 2025 23:01
@bassiounix bassiounix force-pushed the users/bassiounix/spr/10-13-_libc_annex_k_add_rsize_t branch 2 times, most recently from 9b4e574 to e411bb5 Compare October 16, 2025 23:06
@bassiounix bassiounix force-pushed the users/bassiounix/spr/10-13-_libc_annex_k_add_constraint_handler_t branch from 49c7417 to 5a59294 Compare October 16, 2025 23:06
@bassiounix bassiounix force-pushed the users/bassiounix/spr/10-13-_libc_annex_k_add_rsize_t branch from e411bb5 to db9669f Compare October 17, 2025 13:13
@bassiounix bassiounix force-pushed the users/bassiounix/spr/10-13-_libc_annex_k_add_constraint_handler_t branch 2 times, most recently from d836ef1 to b5b13c1 Compare October 18, 2025 13:50
@bassiounix bassiounix force-pushed the users/bassiounix/spr/10-13-_libc_annex_k_add_constraint_handler_t branch from b5b13c1 to 865a661 Compare October 18, 2025 14:40
@bassiounix bassiounix force-pushed the users/bassiounix/spr/10-13-_libc_annex_k_add_rsize_t branch from 02bef79 to 90cf101 Compare October 18, 2025 14:40
@bassiounix bassiounix force-pushed the users/bassiounix/spr/10-13-_libc_annex_k_add_rsize_t branch from 90cf101 to 061abfe Compare October 18, 2025 15:02
@bassiounix bassiounix force-pushed the users/bassiounix/spr/10-13-_libc_annex_k_add_constraint_handler_t branch from 865a661 to 696c143 Compare October 18, 2025 15:02
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.

2 participants