[libc-commits] [libc] [libc] Update C symbols aliasing function declarations. (PR #77034)

via libc-commits libc-commits at lists.llvm.org
Thu Jan 4 17:45:34 PST 2024


https://github.com/lntue created https://github.com/llvm/llvm-project/pull/77034

None

>From 6f4a9a71082fdcfb663aed5c4dd5fc820768a650 Mon Sep 17 00:00:00 2001
From: Tue Ly <lntue.h at gmail.com>
Date: Fri, 5 Jan 2024 01:42:23 +0000
Subject: [PATCH] [libc] Update C symbols aliasing function declarations.

---
 libc/src/__support/common.h | 6 ++++++
 libc/src/stdio/vfprintf.cpp | 5 ++---
 libc/src/stdio/vfprintf.h   | 6 ++++--
 libc/src/stdio/vprintf.cpp  | 3 +--
 libc/src/stdio/vprintf.h    | 4 +++-
 libc/src/stdlib/atof.cpp    | 2 +-
 libc/src/stdlib/atof.h      | 4 +++-
 libc/src/stdlib/bsearch.cpp | 6 ++----
 libc/src/stdlib/bsearch.h   | 7 +++++--
 libc/src/wchar/wctob.cpp    | 2 +-
 libc/src/wchar/wctob.h      | 4 +++-
 11 files changed, 31 insertions(+), 18 deletions(-)

diff --git a/libc/src/__support/common.h b/libc/src/__support/common.h
index 53951dc131c28b..9d7e100edae06b 100644
--- a/libc/src/__support/common.h
+++ b/libc/src/__support/common.h
@@ -20,6 +20,12 @@
 #define LLVM_LIBC_FUNCTION_ATTR
 #endif
 
+#if defined(LIBC_COPT_PUBLIC_PACKAGING)
+#define LIBC_FUNCTION_DECL extern "C"
+#else
+#define LIBC_FUNCTION_DECL
+#endif
+
 // MacOS needs to be excluded because it does not support aliasing.
 #if defined(LIBC_COPT_PUBLIC_PACKAGING) && (!defined(__APPLE__))
 #define LLVM_LIBC_FUNCTION_IMPL(type, name, arglist)                           \
diff --git a/libc/src/stdio/vfprintf.cpp b/libc/src/stdio/vfprintf.cpp
index 2504ce8a20bac5..4406e9aa3b5492 100644
--- a/libc/src/stdio/vfprintf.cpp
+++ b/libc/src/stdio/vfprintf.cpp
@@ -17,9 +17,8 @@
 
 namespace LIBC_NAMESPACE {
 
-LLVM_LIBC_FUNCTION(int, vfprintf,
-                   (::FILE *__restrict stream, const char *__restrict format,
-                    va_list vlist)) {
+int vfprintf(::FILE *__restrict stream, const char *__restrict format,
+             va_list vlist) {
   internal::ArgList args(vlist); // This holder class allows for easier copying
                                  // and pointer semantics, as well as handling
                                  // destruction automatically.
diff --git a/libc/src/stdio/vfprintf.h b/libc/src/stdio/vfprintf.h
index 01827c59d6ce15..61cfb1c4e37f5e 100644
--- a/libc/src/stdio/vfprintf.h
+++ b/libc/src/stdio/vfprintf.h
@@ -12,10 +12,12 @@
 #include <stdarg.h>
 #include <stdio.h>
 
+#include "src/__support/common.h"
+
 namespace LIBC_NAMESPACE {
 
-int vfprintf(::FILE *__restrict stream, const char *__restrict format,
-             va_list vlist);
+LIBC_FUNCTION_DECL int vfprintf(::FILE *__restrict stream,
+                                const char *__restrict format, va_list vlist);
 
 } // namespace LIBC_NAMESPACE
 
diff --git a/libc/src/stdio/vprintf.cpp b/libc/src/stdio/vprintf.cpp
index eff968d1e9134f..6facf0b3b7ffa9 100644
--- a/libc/src/stdio/vprintf.cpp
+++ b/libc/src/stdio/vprintf.cpp
@@ -23,8 +23,7 @@
 
 namespace LIBC_NAMESPACE {
 
-LLVM_LIBC_FUNCTION(int, vprintf,
-                   (const char *__restrict format, va_list vlist)) {
+int vprintf(const char *__restrict format, va_list vlist) {
   internal::ArgList args(vlist); // This holder class allows for easier copying
                                  // and pointer semantics, as well as handling
                                  // destruction automatically.
diff --git a/libc/src/stdio/vprintf.h b/libc/src/stdio/vprintf.h
index fe4252bd86203b..7ddc3b990bdb9f 100644
--- a/libc/src/stdio/vprintf.h
+++ b/libc/src/stdio/vprintf.h
@@ -12,9 +12,11 @@
 #include <stdarg.h>
 #include <stdio.h>
 
+#include "src/__support/common.h"
+
 namespace LIBC_NAMESPACE {
 
-int vprintf(const char *__restrict format, va_list vlist);
+LIBC_FUNCTION_DECL int vprintf(const char *__restrict format, va_list vlist);
 
 } // namespace LIBC_NAMESPACE
 
diff --git a/libc/src/stdlib/atof.cpp b/libc/src/stdlib/atof.cpp
index 61eb7db0056f18..d05c12f791b7dd 100644
--- a/libc/src/stdlib/atof.cpp
+++ b/libc/src/stdlib/atof.cpp
@@ -13,7 +13,7 @@
 
 namespace LIBC_NAMESPACE {
 
-LLVM_LIBC_FUNCTION(double, atof, (const char *str)) {
+double atof(const char *str) {
   auto result = internal::strtofloatingpoint<double>(str);
   if (result.has_error())
     libc_errno = result.error;
diff --git a/libc/src/stdlib/atof.h b/libc/src/stdlib/atof.h
index cc9ae5157d6a52..2d47e6340248cc 100644
--- a/libc/src/stdlib/atof.h
+++ b/libc/src/stdlib/atof.h
@@ -9,9 +9,11 @@
 #ifndef LLVM_LIBC_SRC_STDLIB_ATOF_H
 #define LLVM_LIBC_SRC_STDLIB_ATOF_H
 
+#include "src/__support/common.h"
+
 namespace LIBC_NAMESPACE {
 
-double atof(const char *str);
+LIBC_FUNCTION_DECL double atof(const char *str);
 
 } // namespace LIBC_NAMESPACE
 
diff --git a/libc/src/stdlib/bsearch.cpp b/libc/src/stdlib/bsearch.cpp
index 4292d6b6fe0465..2232d2d9bb4a0e 100644
--- a/libc/src/stdlib/bsearch.cpp
+++ b/libc/src/stdlib/bsearch.cpp
@@ -13,10 +13,8 @@
 
 namespace LIBC_NAMESPACE {
 
-LLVM_LIBC_FUNCTION(void *, bsearch,
-                   (const void *key, const void *array, size_t array_size,
-                    size_t elem_size,
-                    int (*compare)(const void *, const void *))) {
+void *bsearch(const void *key, const void *array, size_t array_size,
+              size_t elem_size, int (*compare)(const void *, const void *)) {
   if (key == nullptr || array == nullptr || array_size == 0 || elem_size == 0)
     return nullptr;
 
diff --git a/libc/src/stdlib/bsearch.h b/libc/src/stdlib/bsearch.h
index 1de7e051ff6c41..6127c2210adaa7 100644
--- a/libc/src/stdlib/bsearch.h
+++ b/libc/src/stdlib/bsearch.h
@@ -11,10 +11,13 @@
 
 #include <stdlib.h>
 
+#include "src/__support/common.h"
+
 namespace LIBC_NAMESPACE {
 
-void *bsearch(const void *key, const void *array, size_t array_size,
-              size_t elem_size, int (*compare)(const void *, const void *));
+LIBC_FUNCTION_DECL void *bsearch(const void *key, const void *array,
+                                 size_t array_size, size_t elem_size,
+                                 int (*compare)(const void *, const void *));
 
 } // namespace LIBC_NAMESPACE
 
diff --git a/libc/src/wchar/wctob.cpp b/libc/src/wchar/wctob.cpp
index 538d5388e50581..babc74ade605c9 100644
--- a/libc/src/wchar/wctob.cpp
+++ b/libc/src/wchar/wctob.cpp
@@ -14,7 +14,7 @@
 
 namespace LIBC_NAMESPACE {
 
-LLVM_LIBC_FUNCTION(int, wctob, (wint_t c)) {
+int wctob(wint_t c) {
   auto result = internal::wctob(c);
   if (result.has_value()) {
     return result.value();
diff --git a/libc/src/wchar/wctob.h b/libc/src/wchar/wctob.h
index 1cc0c211e98a52..614831e09bdd9f 100644
--- a/libc/src/wchar/wctob.h
+++ b/libc/src/wchar/wctob.h
@@ -11,9 +11,11 @@
 
 #include <wchar.h>
 
+#include "src/__support/common.h"
+
 namespace LIBC_NAMESPACE {
 
-int wctob(wint_t c);
+LIBC_FUNCTION_DECL int wctob(wint_t c);
 
 } // namespace LIBC_NAMESPACE
 



More information about the libc-commits mailing list