[libc-commits] [libc] [libc] Use `LIBC_COPT_PUBLIC_PACKAGING` for hermetic and integration tests. (PR #79319)

via libc-commits libc-commits at lists.llvm.org
Fri Jan 26 08:00:47 PST 2024


================
@@ -11,30 +11,44 @@
 
 namespace LIBC_NAMESPACE {
 
-#ifdef LIBC_TARGET_ARCH_IS_GPU
-struct ErrnoConsumer {
-  void operator=(int) {}
+struct Errno {
+  void operator=(int);
+  operator int();
 };
-#endif
 
-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
-// macro defined in LLVM libc's public errno.h header file.
-// TODO: Use a macro to distinguish full build and overlay build which can be
-//       used to exclude __llvmlibc_errno under overlay build.
+} // namespace LIBC_NAMESPACE
+
 #ifdef LIBC_TARGET_ARCH_IS_GPU
-ErrnoConsumer __llvmlibc_errno;
-#else
+// If we are targeting the GPU we currently don't support 'errno'. We simply
+// consume it.
+void LIBC_NAMESPACE::Errno::operator=(int) {}
+LIBC_NAMESPACE::Errno::operator int() { return 0; }
+
+#elif !defined(LIBC_COPT_PUBLIC_PACKAGING)
+// This mode is for unit testing.  We just use another internal errno.
+LIBC_THREAD_LOCAL int __llvmlibc_internal_errno;
+
+void LIBC_NAMESPACE::Errno::operator=(int a) { __llvmlibc_internal_errno = a; }
+LIBC_NAMESPACE::Errno::operator int() { return __llvmlibc_internal_errno; }
+
+#elif defined(LIBC_FULL_BUILD)
+// This mode is for public libc archive, hermetic, and integration tests.
+// In full build mode, we provide all the errno storage ourselves.
----------------
lntue wrote:

Done.

https://github.com/llvm/llvm-project/pull/79319


More information about the libc-commits mailing list