[libc-commits] [libc] [libc] Add __iso99_fscanf alias. (PR #213125)
via libc-commits
libc-commits at lists.llvm.org
Fri Jul 31 07:59:28 PDT 2026
https://github.com/lntue updated https://github.com/llvm/llvm-project/pull/213125
>From 1370b6876395ff3876fd4391280e593a5c2d77ff Mon Sep 17 00:00:00 2001
From: Tue Ly <lntue.h at gmail.com>
Date: Thu, 30 Jul 2026 19:59:22 +0000
Subject: [PATCH 1/2] [libc] Add __iso99_fscanf alias.
---
libc/src/__support/common.h | 17 +++++++++++++++++
libc/src/stdio/baremetal/fscanf.cpp | 5 +++++
2 files changed, 22 insertions(+)
diff --git a/libc/src/__support/common.h b/libc/src/__support/common.h
index d90fe7b8ae98d..e946ee4e0fb20 100644
--- a/libc/src/__support/common.h
+++ b/libc/src/__support/common.h
@@ -56,17 +56,34 @@
__##name##_impl__ asm(c_alias); \
decltype(LIBC_NAMESPACE::name) name [[gnu::alias(c_alias)]]; \
type __##name##_impl__ arglist
+
+#define LLVM_LIBC_ADD_FUNCTION_C_ALIAS(name, c_alias) \
+ extern "C" decltype(LIBC_NAMESPACE::name) c_alias [[gnu::alias(#name)]]; \
+ static_assert(true, "Require semicolon.")
+
#else // __APPLE__
#define LLVM_LIBC_FUNCTION_IMPL_4(type, name, arglist, c_alias) \
LLVM_LIBC_ATTR(name) \
LLVM_LIBC_FUNCTION_ATTR decltype(LIBC_NAMESPACE::name) name asm( \
"_" c_alias); \
type name arglist
+
+// clang-format off
+#define LLVM_LIBC_ADD_FUNCTION_C_ALIAS(name, c_alias) \
+ asm(".text\n" \
+ ".global " "_" #c_alias "\n" \
+ ".type " "_" #c_alias ", @function\n" \
+ "_" #c_alias " = " "_" #name "\n"); \
+ static_assert(true, "Require semicolon.")
+// clang-format on
#endif // __APPLE__
#else // LIBC_COPT_PUBLIC_PACKAGING
#define LLVM_LIBC_FUNCTION_IMPL_4(type, name, arglist, c_alias) \
type name arglist
+
+#define LLVM_LIBC_ADD_FUNCTION_C_ALIAS(name, c_alias)
+
#endif // LIBC_COPT_PUBLIC_PACKAGING
#define LLVM_LIBC_FUNCTION_IMPL_3(type, name, arglist) \
diff --git a/libc/src/stdio/baremetal/fscanf.cpp b/libc/src/stdio/baremetal/fscanf.cpp
index eb8b2326ad6b7..d20dd51cce657 100644
--- a/libc/src/stdio/baremetal/fscanf.cpp
+++ b/libc/src/stdio/baremetal/fscanf.cpp
@@ -36,3 +36,8 @@ LLVM_LIBC_FUNCTION(int, fscanf,
}
} // namespace LIBC_NAMESPACE_DECL
+
+#if ...
+// comments...
+LLVM_LIBC_ADD_FUNCTION_C_ALIAS(fscanf, __isoc99_fscanf);
+#endif
>From 7f08fc197cdad2dd50721f9309f524c17d93c9ce Mon Sep 17 00:00:00 2001
From: Tue Ly <lntue.h at gmail.com>
Date: Fri, 31 Jul 2026 14:58:58 +0000
Subject: [PATCH 2/2] Specify guard.
---
libc/src/stdio/baremetal/fscanf.cpp | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/libc/src/stdio/baremetal/fscanf.cpp b/libc/src/stdio/baremetal/fscanf.cpp
index d20dd51cce657..36ecd27ea0e98 100644
--- a/libc/src/stdio/baremetal/fscanf.cpp
+++ b/libc/src/stdio/baremetal/fscanf.cpp
@@ -37,7 +37,6 @@ LLVM_LIBC_FUNCTION(int, fscanf,
} // namespace LIBC_NAMESPACE_DECL
-#if ...
-// comments...
+#ifdef LIBC_STDIO_ADD_ISO99_FSCANF
LLVM_LIBC_ADD_FUNCTION_C_ALIAS(fscanf, __isoc99_fscanf);
-#endif
+#endif // LIBC_STDIO_ADD_ISO99_FSCANF
More information about the libc-commits
mailing list