|
| 1 | +//===-- Helper macros header for constraint violations ----------*- C++ -*-===// |
| 2 | +// |
| 3 | +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | +// See https://llvm.org/LICENSE.txt for license information. |
| 5 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | +// |
| 7 | +//===----------------------------------------------------------------------===// |
| 8 | + |
| 9 | +#ifndef LLVM_LIBC_SRC___SUPPORT_ANNEX_K_MACROS_H |
| 10 | +#define LLVM_LIBC_SRC___SUPPORT_ANNEX_K_MACROS_H |
| 11 | + |
| 12 | +#include "libc_constraint_handler.h" |
| 13 | +#include "src/__support/libc_errno.h" |
| 14 | + |
| 15 | +#define _CONSTRAINT_VIOLATION(msg, error_code, ret_code) \ |
| 16 | + { \ |
| 17 | + libc_errno = error_code; \ |
| 18 | + libc_constraint_handler(msg, nullptr, error_code); \ |
| 19 | + return ret_code; \ |
| 20 | + } |
| 21 | + |
| 22 | +#define _CONSTRAINT_VIOLATION_IF(expr, error_code, return_code) \ |
| 23 | + { \ |
| 24 | + auto expr_val = expr; \ |
| 25 | + if (expr_val) { \ |
| 26 | + libc_errno = error_code; \ |
| 27 | + libc_constraint_handler(nullptr, nullptr, error_code); \ |
| 28 | + return return_code; \ |
| 29 | + } \ |
| 30 | + } |
| 31 | + |
| 32 | +#define _CONSTRAINT_VIOLATION_CLEANUP_IF(expr, cleanup, error_code, \ |
| 33 | + return_code) \ |
| 34 | + { \ |
| 35 | + auto expr_val = expr; \ |
| 36 | + if (expr_val) { \ |
| 37 | + cleanup; \ |
| 38 | + libc_errno = error_code; \ |
| 39 | + libc_constraint_handler(nullptr, nullptr, error_code); \ |
| 40 | + return return_code; \ |
| 41 | + } \ |
| 42 | + } |
| 43 | + |
| 44 | +#endif // LLVM_LIBC_SRC___SUPPORT_ANNEX_K_MACROS_H |
0 commit comments