[libc-commits] [libc] [libc] Add __iso99_fscanf alias. (PR #213125)

via libc-commits libc-commits at lists.llvm.org
Fri Jul 31 08:07:49 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: lntue

<details>
<summary>Changes</summary>



---
Full diff: https://github.com/llvm/llvm-project/pull/213125.diff


2 Files Affected:

- (modified) libc/src/__support/common.h (+17) 
- (modified) libc/src/stdio/baremetal/fscanf.cpp (+4) 


``````````diff
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..36ecd27ea0e98 100644
--- a/libc/src/stdio/baremetal/fscanf.cpp
+++ b/libc/src/stdio/baremetal/fscanf.cpp
@@ -36,3 +36,7 @@ LLVM_LIBC_FUNCTION(int, fscanf,
 }
 
 } // namespace LIBC_NAMESPACE_DECL
+
+#ifdef LIBC_STDIO_ADD_ISO99_FSCANF
+LLVM_LIBC_ADD_FUNCTION_C_ALIAS(fscanf, __isoc99_fscanf);
+#endif // LIBC_STDIO_ADD_ISO99_FSCANF

``````````

</details>


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


More information about the libc-commits mailing list