Skip to content

[libc] Move __LLVM_LIBC__ define to __llvm-libc-common.h #126877

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 12, 2025

Conversation

petrhosek
Copy link
Member

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.

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.
@llvmbot
Copy link
Member

llvmbot commented Feb 12, 2025

@llvm/pr-subscribers-libc

Author: Petr Hosek (petrhosek)

Changes

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.


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

2 Files Affected:

  • (modified) libc/include/__llvm-libc-common.h (+2)
  • (modified) libc/include/llvm-libc-macros/features-macros.h (-2)
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

@petrhosek
Copy link
Member Author

This issue was raised by @ldionne in #125587. I believe that defining __LLVM_LIBC__ in __llvm-libc-common.h is the simplest solution but I'm open to other suggestions.

@jhuber6
Copy link
Contributor

jhuber6 commented Feb 12, 2025

I'm okay with this, but including features.h and nothing else still needs to define this.

@petrhosek
Copy link
Member Author

I'm okay with this, but including features.h and nothing else still needs to define this.

It will since features.h includes __llvm-libc-common.h.

Copy link
Contributor

@michaelrj-google michaelrj-google left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@petrhosek petrhosek merged commit b0d7820 into llvm:main Feb 12, 2025
15 checks passed
@petrhosek petrhosek added this to the LLVM 20.X Release milestone Feb 12, 2025
@petrhosek
Copy link
Member Author

/cherry-pick b0d7820

@llvmbot
Copy link
Member

llvmbot commented Feb 12, 2025

/pull-request #126960

@petrhosek petrhosek deleted the libc-define branch February 13, 2025 03:32
flovent pushed a commit to flovent/llvm-project that referenced this pull request Feb 13, 2025
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.
@@ -9,6 +9,4 @@
#ifndef LLVM_LIBC_MACROS_FEATURES_MACROS_H
#define LLVM_LIBC_MACROS_FEATURES_MACROS_H

#define __LLVM_LIBC__ 1

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps we should have just deleted this file? It's literally only now empty header guards.

joaosaffran pushed a commit to joaosaffran/llvm-project that referenced this pull request Feb 14, 2025
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.
redstar pushed a commit to redstar/llvm-project that referenced this pull request Feb 14, 2025
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.

(cherry picked from commit b0d7820)
sivan-shani pushed a commit to sivan-shani/llvm-project that referenced this pull request Feb 24, 2025
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Development

Successfully merging this pull request may close these issues.

5 participants