[libc-commits] [libc] d30de98 - [libc] Define LLVM_LIBC_FUNCTION with a layer of macro expansion

Roland McGrath via libc-commits libc-commits at lists.llvm.org
Sat Mar 25 11:31:48 PDT 2023


Author: Roland McGrath
Date: 2023-03-25T11:30:48-07:00
New Revision: d30de9844e1a9f1e77677b8cf4a7f4db977c0c9f

URL: https://github.com/llvm/llvm-project/commit/d30de9844e1a9f1e77677b8cf4a7f4db977c0c9f
DIFF: https://github.com/llvm/llvm-project/commit/d30de9844e1a9f1e77677b8cf4a7f4db977c0c9f.diff

LOG: [libc] Define LLVM_LIBC_FUNCTION with a layer of macro expansion

Move the real LLVM_LIBC_FUNCTION macro definitions to
LLVM_LIBC_FUNCTION_IMPL and make LLVM_LIBC_FUNCTION a wrapper to
expand macros in its arguments.  This makes it possible to
compile libc implementation and test files with -Dfunc=othername.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D146863

Added: 
    

Modified: 
    libc/src/__support/common.h

Removed: 
    


################################################################################
diff  --git a/libc/src/__support/common.h b/libc/src/__support/common.h
index 6d1110dbd27de..300d2bc8b2a4f 100644
--- a/libc/src/__support/common.h
+++ b/libc/src/__support/common.h
@@ -18,21 +18,25 @@
 
 // GPU targets do not support aliasing.
 #if defined(LIBC_COPT_PUBLIC_PACKAGING) && defined(LIBC_TARGET_ARCH_IS_GPU)
-#define LLVM_LIBC_FUNCTION(type, name, arglist)                                \
+#define LLVM_LIBC_FUNCTION_IMPL(type, name, arglist)                           \
   LLVM_LIBC_FUNCTION_ATTR decltype(__llvm_libc::name)                          \
       __##name##_impl__ __asm__(#name);                                        \
   type __##name##_impl__ arglist
 // MacOS needs to be excluded because it does not support aliasing.
 #elif defined(LIBC_COPT_PUBLIC_PACKAGING) && (!defined(__APPLE__))
-#define LLVM_LIBC_FUNCTION(type, name, arglist)                                \
+#define LLVM_LIBC_FUNCTION_IMPL(type, name, arglist)                           \
   LLVM_LIBC_FUNCTION_ATTR decltype(__llvm_libc::name)                          \
       __##name##_impl__ __asm__(#name);                                        \
   decltype(__llvm_libc::name) name [[gnu::alias(#name)]];                      \
   type __##name##_impl__ arglist
 #else
-#define LLVM_LIBC_FUNCTION(type, name, arglist) type name arglist
+#define LLVM_LIBC_FUNCTION_IMPL(type, name, arglist) type name arglist
 #endif
 
+// This extra layer of macro allows `name` to be a macro to rename a function.
+#define LLVM_LIBC_FUNCTION(type, name, arglist)                                \
+  LLVM_LIBC_FUNCTION_IMPL(type, name, arglist)
+
 namespace __llvm_libc {
 namespace internal {
 constexpr bool same_string(char const *lhs, char const *rhs) {


        


More information about the libc-commits mailing list