https://github.com/bassiounix updated https://github.com/llvm/llvm-project/pull/164093
>From 8c97552d0f12a7393ab13fe794b21ed3da7e009b Mon Sep 17 00:00:00 2001 From: bassiounix <[email protected]> Date: Tue, 14 Oct 2025 07:06:06 +0300 Subject: [PATCH] [libc][stdlib][annex_k] Add set_constraint_handler_s. --- libc/config/linux/aarch64/entrypoints.txt | 1 + libc/config/linux/riscv/entrypoints.txt | 1 + libc/config/linux/x86_64/entrypoints.txt | 1 + libc/include/stdlib.yaml | 7 +++++ libc/src/stdlib/CMakeLists.txt | 11 ++++++++ libc/src/stdlib/set_constraint_handler_s.cpp | 28 ++++++++++++++++++++ libc/src/stdlib/set_constraint_handler_s.h | 21 +++++++++++++++ 7 files changed, 70 insertions(+) create mode 100644 libc/src/stdlib/set_constraint_handler_s.cpp create mode 100644 libc/src/stdlib/set_constraint_handler_s.h diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt index f99686d81d9a7b..5b902529bd30ce 100644 --- a/libc/config/linux/aarch64/entrypoints.txt +++ b/libc/config/linux/aarch64/entrypoints.txt @@ -1400,6 +1400,7 @@ if(LLVM_LIBC_FULL_BUILD) libc.src.stdlib.system libc.src.stdlib.unsetenv libc.src.stdlib.quick_exit + libc.src.stdlib.set_constraint_handler_s # signal.h entrypoints libc.src.signal.kill diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt index e44725e0bc39cb..00371d2fd95458 100644 --- a/libc/config/linux/riscv/entrypoints.txt +++ b/libc/config/linux/riscv/entrypoints.txt @@ -1584,6 +1584,7 @@ if(LLVM_LIBC_FULL_BUILD) libc.src.stdlib.mbtowc libc.src.stdlib.mblen libc.src.stdlib.quick_exit + libc.src.stdlib.set_constraint_handler_s libc.src.stdlib.wcstombs libc.src.stdlib.wctomb diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt index 257cde1e4e1db9..8990c3c6a90ebc 100644 --- a/libc/config/linux/x86_64/entrypoints.txt +++ b/libc/config/linux/x86_64/entrypoints.txt @@ -1609,6 +1609,7 @@ if(LLVM_LIBC_FULL_BUILD) libc.src.stdlib.mbtowc libc.src.stdlib.mblen libc.src.stdlib.quick_exit + libc.src.stdlib.set_constraint_handler_s libc.src.stdlib.system libc.src.stdlib.wcstombs libc.src.stdlib.wctomb diff --git a/libc/include/stdlib.yaml b/libc/include/stdlib.yaml index dc761a12bf8071..a00b21c779659a 100644 --- a/libc/include/stdlib.yaml +++ b/libc/include/stdlib.yaml @@ -275,6 +275,13 @@ functions: - type: void *__restrict - type: errno_t guard: 'LIBC_HAS_ANNEX_K' + - name: set_constraint_handler_s + standards: + - stdc + return_type: constraint_handler_t + arguments: + - type: constraint_handler_t + guard: 'LIBC_HAS_ANNEX_K' - name: srand standards: - stdc diff --git a/libc/src/stdlib/CMakeLists.txt b/libc/src/stdlib/CMakeLists.txt index 5e88b1aeda7672..7fbf6119311e77 100644 --- a/libc/src/stdlib/CMakeLists.txt +++ b/libc/src/stdlib/CMakeLists.txt @@ -931,6 +931,17 @@ add_entrypoint_object( .${LIBC_TARGET_OS}.system ) +add_entrypoint_object( + set_constraint_handler_s + SRCS + set_constraint_handler_s.cpp + HDRS + set_constraint_handler_s.h + DEPENDS + libc.src.__support.annex_k.abort_handler_s + libc.src.__support.annex_k.libc_constraint_handler +) + add_entrypoint_object( ignore_handler_s HDRS diff --git a/libc/src/stdlib/set_constraint_handler_s.cpp b/libc/src/stdlib/set_constraint_handler_s.cpp new file mode 100644 index 00000000000000..d3a16d77e3b0a3 --- /dev/null +++ b/libc/src/stdlib/set_constraint_handler_s.cpp @@ -0,0 +1,28 @@ +//===-- Implementation of set_constraint_handler_s ------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#include "set_constraint_handler_s.h" +#include "src/__support/annex_k/abort_handler_s.h" +#include "src/__support/annex_k/libc_constraint_handler.h" + +namespace LIBC_NAMESPACE_DECL { + +LLVM_LIBC_FUNCTION(constraint_handler_t, set_constraint_handler_s, + (constraint_handler_t handler)) { + auto previous_handler = annex_k::libc_constraint_handler; + + if (!handler) { + annex_k::libc_constraint_handler = &annex_k::abort_handler_s; + } else { + annex_k::libc_constraint_handler = handler; + } + + return previous_handler; +} + +} // namespace LIBC_NAMESPACE_DECL diff --git a/libc/src/stdlib/set_constraint_handler_s.h b/libc/src/stdlib/set_constraint_handler_s.h new file mode 100644 index 00000000000000..f5c6e01712ef06 --- /dev/null +++ b/libc/src/stdlib/set_constraint_handler_s.h @@ -0,0 +1,21 @@ +//===-- Implementation header for set_constraint_handler_s ------*- C++ -*-===// +// +// 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_SRC_STDLIB_SET_CONSTRAINT_HANDLER_S_H +#define LLVM_LIBC_SRC_STDLIB_SET_CONSTRAINT_HANDLER_S_H + +#include "hdr/types/constraint_handler_t.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { + +constraint_handler_t set_constraint_handler_s(constraint_handler_t handler); + +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC_STDLIB_SET_CONSTRAINT_HANDLER_S_H _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
