[libc-commits] [libc] [libc] Move __LLVM_LIBC__ define to __llvm-libc-common.h (PR #126877)

Petr Hosek via libc-commits libc-commits at lists.llvm.org
Wed Feb 12 01:16:00 PST 2025


https://github.com/petrhosek created https://github.com/llvm/llvm-project/pull/126877

Relying on features.h is problematic since codebases are free to have such a header on their search path, which breaks compilation. libc should instead provide a more standard way of getting __LLVM_LIBC__. Since __llvm-libc-common.h is included from all libc headers, defining __LLVM_LIBC__ there ensures that this define is available whenever any of the standard header is included.

>From e02440f46e40e81bbf0bced96c602ecf95ab6a30 Mon Sep 17 00:00:00 2001
From: Petr Hosek <phosek at google.com>
Date: Wed, 12 Feb 2025 09:11:14 +0000
Subject: [PATCH] [libc] Move __LLVM_LIBC__ define to __llvm-libc-common.h

Relying on features.h is problematic since codebases are free to have
such a header on their search path, which breaks compilation. libc
should instead provide a more standard way of getting __LLVM_LIBC__.
Since __llvm-libc-common.h is included from all libc headers, defining
__LLVM_LIBC__ there ensures that this define is available whenever any
of the standard header is included.
---
 libc/include/__llvm-libc-common.h               | 2 ++
 libc/include/llvm-libc-macros/features-macros.h | 2 --
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/libc/include/__llvm-libc-common.h b/libc/include/__llvm-libc-common.h
index d3f8a4e63268a..a0fa506c01ab8 100644
--- a/libc/include/__llvm-libc-common.h
+++ b/libc/include/__llvm-libc-common.h
@@ -9,6 +9,8 @@
 #ifndef LLVM_LIBC_COMMON_H
 #define LLVM_LIBC_COMMON_H
 
+#define __LLVM_LIBC__ 1
+
 #ifdef __cplusplus
 
 #undef __BEGIN_C_DECLS
diff --git a/libc/include/llvm-libc-macros/features-macros.h b/libc/include/llvm-libc-macros/features-macros.h
index 5bc87a68fc0ba..f87ae4ad12408 100644
--- a/libc/include/llvm-libc-macros/features-macros.h
+++ b/libc/include/llvm-libc-macros/features-macros.h
@@ -9,6 +9,4 @@
 #ifndef LLVM_LIBC_MACROS_FEATURES_MACROS_H
 #define LLVM_LIBC_MACROS_FEATURES_MACROS_H
 
-#define __LLVM_LIBC__ 1
-
 #endif // LLVM_LIBC_MACROS_FEATURES_MACROS_H



More information about the libc-commits mailing list