[llvm-branch-commits] [libc] [libc][annex_k] Add libc_constraint_handler macros. (PR #164092)
Muhammad Bassiouni via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Sat Oct 18 07:40:41 PDT 2025
https://github.com/bassiounix updated https://github.com/llvm/llvm-project/pull/164092
>From b2f54c03c48a8484b8fea39c5a45e8ae273eecec Mon Sep 17 00:00:00 2001
From: bassiounix <muhammad.m.bassiouni at gmail.com>
Date: Tue, 14 Oct 2025 06:45:09 +0300
Subject: [PATCH] [libc][annex_k] Add libc_constraint_handler macros.
---
libc/src/__support/annex_k/CMakeLists.txt | 9 ++++
.../src/__support/annex_k/constraint_macros.h | 44 +++++++++++++++++++
2 files changed, 53 insertions(+)
create mode 100644 libc/src/__support/annex_k/constraint_macros.h
diff --git a/libc/src/__support/annex_k/CMakeLists.txt b/libc/src/__support/annex_k/CMakeLists.txt
index 8eb65f2469b4f..4ef4e32ebdd85 100644
--- a/libc/src/__support/annex_k/CMakeLists.txt
+++ b/libc/src/__support/annex_k/CMakeLists.txt
@@ -11,6 +11,15 @@ add_header_library(
libc.src.stdlib.abort
)
+add_header_library(
+ constraint_macros
+ HDRS
+ constraint_macros.h
+ DEPENDS
+ .libc_constraint_handler
+ libc.src.__support.libc_errno
+)
+
add_header_library(
libc_constraint_handler
HDRS
diff --git a/libc/src/__support/annex_k/constraint_macros.h b/libc/src/__support/annex_k/constraint_macros.h
new file mode 100644
index 0000000000000..835c161dd0d30
--- /dev/null
+++ b/libc/src/__support/annex_k/constraint_macros.h
@@ -0,0 +1,44 @@
+//===-- Helper macros header for constraint violations ----------*- 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___SUPPORT_ANNEX_K_MACROS_H
+#define LLVM_LIBC_SRC___SUPPORT_ANNEX_K_MACROS_H
+
+#include "libc_constraint_handler.h"
+#include "src/__support/libc_errno.h"
+
+#define _CONSTRAINT_VIOLATION(msg, error_code, ret_code) \
+ { \
+ libc_errno = error_code; \
+ libc_constraint_handler(msg, nullptr, error_code); \
+ return ret_code; \
+ }
+
+#define _CONSTRAINT_VIOLATION_IF(expr, error_code, return_code) \
+ { \
+ auto expr_val = expr; \
+ if (expr_val) { \
+ libc_errno = error_code; \
+ libc_constraint_handler(nullptr, nullptr, error_code); \
+ return return_code; \
+ } \
+ }
+
+#define _CONSTRAINT_VIOLATION_CLEANUP_IF(expr, cleanup, error_code, \
+ return_code) \
+ { \
+ auto expr_val = expr; \
+ if (expr_val) { \
+ cleanup; \
+ libc_errno = error_code; \
+ libc_constraint_handler(nullptr, nullptr, error_code); \
+ return return_code; \
+ } \
+ }
+
+#endif // LLVM_LIBC_SRC___SUPPORT_ANNEX_K_MACROS_H
More information about the llvm-branch-commits
mailing list