[libc-commits] [libc] [libc] Add `scanf` support to the GPU build (PR #104812)

Michael Jones via libc-commits libc-commits at lists.llvm.org
Tue Aug 20 11:37:22 PDT 2024


================
@@ -12,17 +12,41 @@
 #include "src/__support/File/file.h"
 #include "src/__support/arg_list.h"
 #include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/architectures.h"
 #include "src/stdio/scanf_core/reader.h"
 #include "src/stdio/scanf_core/scanf_main.h"
 
+#if defined(LIBC_TARGET_ARCH_IS_GPU)
+#include "src/stdio/ferror.h"
+#include "src/stdio/getc.h"
+#include "src/stdio/ungetc.h"
+#endif
+
 #include "hdr/types/FILE.h"
 #include <stddef.h>
 
 namespace LIBC_NAMESPACE_DECL {
 
 namespace internal {
 
-#ifndef LIBC_COPT_STDIO_USE_SYSTEM_FILE
+#if defined(LIBC_TARGET_ARCH_IS_GPU)
+// Since ungetc_unlocked isn't always available, we don't acquire the lock for
+// system files.
+LIBC_INLINE void flockfile(::FILE *) { return; }
+
+LIBC_INLINE void funlockfile(::FILE *) { return; }
+
+LIBC_INLINE int getc(void *f) {
+  return LIBC_NAMESPACE::getc(reinterpret_cast<::FILE *>(f));
----------------
michaelrj-google wrote:

the namespace isn't the issue, it's the fact that it makes entrypoints less independent. If entrypoints include each other directly then you have to include them as a group, you can't just get scanf without ungetc. This causes problems when trying to rollout individual functions.

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


More information about the libc-commits mailing list