[libc-commits] [libc] [libc] Fix 'fgets' test on the GPU for some C libraries (PR #110118)

Joseph Huber via libc-commits libc-commits at lists.llvm.org
Thu Sep 26 05:42:51 PDT 2024


https://github.com/jhuber6 created https://github.com/llvm/llvm-project/pull/110118

Summary:
The GPU handling for a lot of `FILE *` functions pretty much just
forwards it to the host via RPC. This test checks for implementation
defined behavior, which sometimes passes and sometimes doesn't. We just
disable it here so it works on the standard semantics.

We do this forwarding primarily for interopt w/ the host if the user is
compiling from an offloading language (e.g. CUDA).


>From 87526cedff22fbb7bf94151ade9306224183a5ae Mon Sep 17 00:00:00 2001
From: Joseph Huber <huberjn at outlook.com>
Date: Thu, 26 Sep 2024 07:38:23 -0500
Subject: [PATCH] [libc] Fix 'fgets' test on the GPU for some C libraries

Summary:
The GPU handling for a lot of `FILE *` functions pretty much just
forwards it to the host via RPC. This test checks for implementation
defined behavior, which sometimes passes and sometimes doesn't. We just
disable it here so it works on the standard semantics.

We do this forwarding primarily for interopt w/ the host if the user is
compiling from an offloading language (e.g. CUDA).
---
 libc/test/src/stdio/fgets_test.cpp | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libc/test/src/stdio/fgets_test.cpp b/libc/test/src/stdio/fgets_test.cpp
index d005a71710d21a..39337262f1e008 100644
--- a/libc/test/src/stdio/fgets_test.cpp
+++ b/libc/test/src/stdio/fgets_test.cpp
@@ -43,6 +43,8 @@ TEST(LlvmLibcFgetsTest, WriteAndReadCharacters) {
   file = LIBC_NAMESPACE::fopen(FILENAME, "r");
   ASSERT_FALSE(file == nullptr);
 
+  // The GPU build relies on the host C library, so this check may be different.
+#ifndef LIBC_TARGET_ARCH_IS_GPU
   // If we request just 1 byte, it should return just a null byte and not
   // advance the read head. This is implementation defined.
   output = LIBC_NAMESPACE::fgets(buff, 1, file);
@@ -54,6 +56,7 @@ TEST(LlvmLibcFgetsTest, WriteAndReadCharacters) {
   // This is also implementation defined.
   output = LIBC_NAMESPACE::fgets(buff, 0, file);
   ASSERT_TRUE(output == nullptr);
+#endif
 
   const char *output_arr[] = {
       "1234567", "89\n", "1234567", "\n", "123456\n", "1",



More information about the libc-commits mailing list