Skip to content

[libc++] Guard include of <features.h> with __has_include #127691

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 19, 2025

Conversation

ldionne
Copy link
Member

@ldionne ldionne commented Feb 18, 2025

Some configurations define AMDGPU or NVPTX on platforms that don't provide <features.h>, such as CUDA on Mac.

Some configurations define __AMDGPU__ or __NVPTX__ on platforms
that don't provide <features.h>, such as CUDA on Mac.
@ldionne ldionne requested a review from a team as a code owner February 18, 2025 19:40
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Feb 18, 2025
@llvmbot
Copy link
Member

llvmbot commented Feb 18, 2025

@llvm/pr-subscribers-libcxx

Author: Louis Dionne (ldionne)

Changes

Some configurations define AMDGPU or NVPTX on platforms that don't provide <features.h>, such as CUDA on Mac.


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

1 Files Affected:

  • (modified) libcxx/include/__configuration/platform.h (+8-6)
diff --git a/libcxx/include/__configuration/platform.h b/libcxx/include/__configuration/platform.h
index cff99376ee24b..8d0f8f63f5213 100644
--- a/libcxx/include/__configuration/platform.h
+++ b/libcxx/include/__configuration/platform.h
@@ -32,12 +32,14 @@
 
 // Need to detect which libc we're using if we're on Linux.
 #if defined(__linux__) || defined(__AMDGPU__) || defined(__NVPTX__)
-#  include <features.h>
-#  if defined(__GLIBC_PREREQ)
-#    define _LIBCPP_GLIBC_PREREQ(a, b) __GLIBC_PREREQ(a, b)
-#  else
-#    define _LIBCPP_GLIBC_PREREQ(a, b) 0
-#  endif // defined(__GLIBC_PREREQ)
+#  if __has_include(<features.h>)
+#    include <features.h>
+#    if defined(__GLIBC_PREREQ)
+#      define _LIBCPP_GLIBC_PREREQ(a, b) __GLIBC_PREREQ(a, b)
+#    else
+#      define _LIBCPP_GLIBC_PREREQ(a, b) 0
+#    endif // defined(__GLIBC_PREREQ)
+#  endif
 #endif
 
 #ifndef __BYTE_ORDER__

@ldionne ldionne added this to the LLVM 20.X Release milestone Feb 18, 2025
@jhuber6
Copy link
Contributor

jhuber6 commented Feb 18, 2025

Yeah, I forgot to mention that offloading compilations are weird. They like to define conflicting macros on both sides of the compilation to make things look the same.

@ldionne ldionne merged commit 2c8b124 into llvm:main Feb 19, 2025
84 checks passed
@ldionne ldionne deleted the review/guard-features-include-more branch February 19, 2025 13:22
@ldionne
Copy link
Member Author

ldionne commented Feb 19, 2025

/cherry-pick 2c8b124

@llvmbot
Copy link
Member

llvmbot commented Feb 19, 2025

Failed to cherry-pick: 2c8b124

https://github.com/llvm/llvm-project/actions/runs/13413622290

Please manually backport the fix and push it to your github fork. Once this is done, please create a pull request

@ldionne
Copy link
Member Author

ldionne commented Feb 19, 2025

/cherry-pick 2c8b124

@llvmbot
Copy link
Member

llvmbot commented Feb 19, 2025

/pull-request #127842

swift-ci pushed a commit to swiftlang/llvm-project that referenced this pull request Feb 20, 2025
Some configurations define __AMDGPU__ or __NVPTX__ on platforms that
don't provide <features.h>, such as CUDA on Mac.

(cherry picked from commit 2c8b124)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
Development

Successfully merging this pull request may close these issues.

3 participants