[libc-commits] [libc] [libc] Fix LLVM_LIBC_ADD_FUNCTION_C_ALIAS lint namespace error (PR #240751)

Jeff Bailey via libc-commits libc-commits at lists.llvm.org
Tue Nov 10 00:18:05 PST 2026


https://github.com/kaladron created https://github.com/llvm/llvm-project/pull/240751

When LIBC_COPT_PUBLIC_PACKAGING is disabled, as in internal object targets linted by libc-lint, LLVM_LIBC_ADD_FUNCTION_C_ALIAS expanded to static_assert(true, "Require semicolon.").  Because callers place this macro at translation-unit scope outside LIBC_NAMESPACE_DECL, llvmlibc-implementation-in-namespace rejected the static_assert declaration in libc/src/errno/libc_errno.cpp and the scanf sources.

Replace that stub with an extern "C" type alias referring to LIBC_NAMESPACE::name.  ImplementationInNamespaceCheck already exempts extern "C" linkage specifications at file scope, the semicolon requirement is preserved, and the referenced internal symbol is still verified at compile time.

Assisted-by: Automated tooling, human reviewed.

>From cff46117167f73a78af2ff5da25dcec7397ec966 Mon Sep 17 00:00:00 2001
From: Jeff Bailey <jbailey at raspberryginger.com>
Date: Mon, 9 Nov 2026 22:50:02 +0000
Subject: [PATCH] [libc] Fix LLVM_LIBC_ADD_FUNCTION_C_ALIAS lint namespace
 error

When LIBC_COPT_PUBLIC_PACKAGING is disabled, as in internal object
targets linted by libc-lint, LLVM_LIBC_ADD_FUNCTION_C_ALIAS expanded to
static_assert(true, "Require semicolon.").  Because callers place this
macro at translation-unit scope outside LIBC_NAMESPACE_DECL,
llvmlibc-implementation-in-namespace rejected the static_assert
declaration in libc/src/errno/libc_errno.cpp and the scanf sources.

Replace that stub with an extern "C" type alias referring to
LIBC_NAMESPACE::name.  ImplementationInNamespaceCheck already exempts
extern "C" linkage specifications at file scope, the semicolon
requirement is preserved, and the referenced internal symbol is still
verified at compile time.

Assisted-by: Automated tooling, human reviewed.
---
 libc/src/__support/common.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/libc/src/__support/common.h b/libc/src/__support/common.h
index 8ad3d22aa49485..d1d52c3b50e619 100644
--- a/libc/src/__support/common.h
+++ b/libc/src/__support/common.h
@@ -87,8 +87,11 @@
 #define LLVM_LIBC_FUNCTION_IMPL_4(type, name, arglist, c_alias)                \
   type name arglist
 
+// Add an extra C alias `c_alias` for `LIBC_NAMESPACE::name` at file scope when
+// a function needs multiple exported names (omitted in non-packaging builds).
 #define LLVM_LIBC_ADD_FUNCTION_C_ALIAS(name, c_alias)                          \
-  static_assert(true, "Require semicolon.")
+  extern "C" using __llvm_libc_unused_alias_##c_alias =                        \
+      decltype(LIBC_NAMESPACE::name)
 
 #endif // LIBC_COPT_PUBLIC_PACKAGING
 



More information about the libc-commits mailing list