mirror of
https://github.com/intel/llvm.git
synced 2026-01-24 17:01:00 +08:00
[libc] Make libc_errno point to internal errno for non-public builds.
The macro llvmlibc_errno has also been removed. This change completes the switch to using a hermetic errno for unit tests. Fixes #61037 Reviewed By: lntue Differential Revision: https://reviews.llvm.org/D146005
This commit is contained in:
@@ -4,7 +4,6 @@ add_entrypoint_object(
|
||||
libc_errno.cpp
|
||||
HDRS
|
||||
libc_errno.h # Include this
|
||||
llvmlibc_errno.h # DEPRECATED: Will be removed soon
|
||||
DEPENDS
|
||||
libc.include.errno
|
||||
)
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
namespace __llvm_libc {
|
||||
|
||||
extern "C" {
|
||||
#ifdef LIBC_COPT_PUBLIC_PACKAGING
|
||||
// TODO: Declare __llvmlibc_errno only under LIBC_COPT_PUBLIC_PACKAGING and
|
||||
// __llvmlibc_internal_errno otherwise.
|
||||
//
|
||||
// In overlay mode, this will be an unused thread local variable as libc_errno
|
||||
// will resolve to errno from the system libc's errno.h. In full build mode
|
||||
// however, libc_errno will resolve to this thread local variable via the errno
|
||||
@@ -19,7 +19,9 @@ extern "C" {
|
||||
// TODO: Use a macro to distinguish full build and overlay build which can be
|
||||
// used to exclude __llvmlibc_errno under overlay build.
|
||||
thread_local int __llvmlibc_errno;
|
||||
#else
|
||||
thread_local int __llvmlibc_internal_errno;
|
||||
#endif
|
||||
} // extern "C"
|
||||
|
||||
} // namespace __llvm_libc
|
||||
|
||||
@@ -29,7 +29,7 @@ extern thread_local int __llvmlibc_internal_errno;
|
||||
// libc_errno, this header file will be "shipped" via an add_entrypoint_object
|
||||
// target. At which point libc_errno, should point to __llvmlibc_internal_errno
|
||||
// if LIBC_COPT_PUBLIC_PACKAGING is not defined.
|
||||
#define libc_errno errno
|
||||
#define libc_errno __llvm_libc::__llvmlibc_internal_errno
|
||||
|
||||
} // namespace __llvm_libc
|
||||
#endif
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
//===-- Implementation header for errno -------------------------*- 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_ERRNO_LLVMLIBC_ERRNO_H
|
||||
#define LLVM_LIBC_SRC_ERRNO_LLVMLIBC_ERRNO_H
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
// DEPRECATED: Use libc_errno from libc_errno.h instead. This macro is only
|
||||
// present to facilitate gradual transition (as in, in multiple simple patches)
|
||||
// to libc_errno.
|
||||
// TODO: After all of libc/src and libc/test is switched over to use libc_errno,
|
||||
// remove this macro and header file.
|
||||
#define llvmlibc_errno errno
|
||||
|
||||
#endif // LLVM_LIBC_SRC_ERRNO_LLVMLIBC_ERRNO_H
|
||||
@@ -9,6 +9,8 @@ add_header_library(
|
||||
errno_setter_matcher
|
||||
HDRS
|
||||
ErrnoSetterMatcher.h
|
||||
DEPENDS
|
||||
libc.src.errno.errno
|
||||
)
|
||||
|
||||
add_custom_target(check-libc)
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
#ifndef LLVM_LIBC_TEST_ERRNOSETTERMATCHER_H
|
||||
#define LLVM_LIBC_TEST_ERRNOSETTERMATCHER_H
|
||||
|
||||
#include "src/errno/libc_errno.h"
|
||||
#include "test/UnitTest/Test.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
namespace __llvm_libc {
|
||||
@@ -42,8 +42,8 @@ public:
|
||||
|
||||
bool match(T Got) {
|
||||
ActualReturn = Got;
|
||||
ActualErrno = errno;
|
||||
errno = 0;
|
||||
ActualErrno = libc_errno;
|
||||
libc_errno = 0;
|
||||
return Got == ExpectedReturn && ActualErrno == ExpectedErrno;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user