[libc-commits] [libc] 8bd723b - [libc] Add fuchsia/io.h for TestLogger

Alex Brachet via libc-commits libc-commits at lists.llvm.org
Tue Apr 18 17:55:15 PDT 2023


Author: Alex Brachet
Date: 2023-04-19T00:54:32Z
New Revision: 8bd723b0714bf00330e727510130a635e3cb477f

URL: https://github.com/llvm/llvm-project/commit/8bd723b0714bf00330e727510130a635e3cb477f
DIFF: https://github.com/llvm/llvm-project/commit/8bd723b0714bf00330e727510130a635e3cb477f.diff

LOG: [libc] Add fuchsia/io.h for TestLogger

b3c696fb86 started using TestLogger in tests. This class depends on
write_to_stderr which was previously only provided for Linux and
GPU's. Note, this function is used on those platforms in the libc
proper, though for Fuchsia we only ever want to provide this for
TestLogger.

No CMake files are changed because this fuchsia/ directory isn't
useful in any CMake build.

Differential Revision: https://reviews.llvm.org/D148675

Added: 
    libc/src/__support/OSUtil/fuchsia/io.h

Modified: 
    libc/src/__support/OSUtil/io.h

Removed: 
    


################################################################################
diff  --git a/libc/src/__support/OSUtil/fuchsia/io.h b/libc/src/__support/OSUtil/fuchsia/io.h
new file mode 100644
index 0000000000000..150d92d56eb65
--- /dev/null
+++ b/libc/src/__support/OSUtil/fuchsia/io.h
@@ -0,0 +1,28 @@
+//===------------- Fuchsia implementation of IO utils -----------*- 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_OSUTIL_FUCHSIA_IO_H
+#define LLVM_LIBC_SRC_SUPPORT_OSUTIL_FUCHSIA_IO_H
+
+#ifndef LIBC_COPT_TEST_USE_FUCHSIA
+#error this file should only be used by tests
+#endif
+
+#include "src/__support/CPP/string_view.h"
+
+#include <zircon/sanitizer.h>
+
+namespace __llvm_libc {
+
+LIBC_INLINE void write_to_stderr(cpp::string_view msg) {
+  __sanitizer_log_write(msg.data(), msg.size());
+}
+
+} // namespace __llvm_libc
+
+#endif // LLVM_LIBC_SRC_SUPPORT_OSUTIL_FUCHSIA_IO_H

diff  --git a/libc/src/__support/OSUtil/io.h b/libc/src/__support/OSUtil/io.h
index e2eee0826b177..7727bd5d29ac8 100644
--- a/libc/src/__support/OSUtil/io.h
+++ b/libc/src/__support/OSUtil/io.h
@@ -15,6 +15,8 @@
 #include "gpu/io.h"
 #elif defined(__unix__)
 #include "linux/io.h"
+#elif defined(__Fuchsia__)
+#include "fuchsia/io.h"
 #endif
 
 #endif // LLVM_LIBC_SRC_SUPPORT_OSUTIL_IO_H


        


More information about the libc-commits mailing list