Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libc / src / errno / libc_errno.h
blobfbcd1c3395cd1fdc43327d84c4c5a0415d0fd19b
1 //===-- Implementation header for errno -------------------------*- 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 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_LIBC_SRC_ERRNO_LIBC_ERRNO_H
10 #define LLVM_LIBC_SRC_ERRNO_LIBC_ERRNO_H
12 #include "src/__support/macros/attributes.h"
13 #include "src/__support/macros/properties/architectures.h"
15 #include <errno.h>
17 // If we are targeting the GPU we currently don't support 'errno'. We simply
18 // consume it.
19 #ifdef LIBC_TARGET_ARCH_IS_GPU
20 namespace LIBC_NAMESPACE {
21 struct ErrnoConsumer {
22 void operator=(int) {}
24 } // namespace LIBC_NAMESPACE
25 #endif
27 // All of the libc runtime and test code should use the "libc_errno" macro. They
28 // should not refer to the "errno" macro directly.
29 #ifdef LIBC_COPT_PUBLIC_PACKAGING
30 #ifdef LIBC_TARGET_ARCH_IS_GPU
31 extern "C" LIBC_NAMESPACE::ErrnoConsumer __llvmlibc_errno;
32 #define libc_errno __llvmlibc_errno
33 #else
34 // This macro will resolve to errno from the errno.h file included above. Under
35 // full build, this will be LLVM libc's errno. In overlay build, it will be
36 // system libc's errno.
37 #define libc_errno errno
38 #endif
39 #else
40 namespace LIBC_NAMESPACE {
42 // TODO: On the GPU build this will be mapped to a single global value. We need
43 // to ensure that tests are not run with multiple threads that depend on errno
44 // until we have true 'thread_local' support on the GPU.
45 extern "C" LIBC_THREAD_LOCAL int __llvmlibc_internal_errno;
47 // TODO: After all of libc/src and libc/test are switched over to use
48 // libc_errno, this header file will be "shipped" via an add_entrypoint_object
49 // target. At which point libc_errno, should point to __llvmlibc_internal_errno
50 // if LIBC_COPT_PUBLIC_PACKAGING is not defined.
51 #define libc_errno LIBC_NAMESPACE::__llvmlibc_internal_errno
53 } // namespace LIBC_NAMESPACE
54 #endif
56 #endif // LLVM_LIBC_SRC_ERRNO_LIBC_ERRNO_H