[llvm-branch-commits] [libcxx] release/20.x: [libc++] Guard include of <features.h> with __has_include (#127691) (PR #127842)

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Feb 19 10:24:07 PST 2025


https://github.com/llvmbot created https://github.com/llvm/llvm-project/pull/127842

Backport 2c8b1248513624e89b510397224f0f405116f3d3

Requested by: @ldionne

>From 315226cf7b7751303615984ec3d84664d7777156 Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Wed, 19 Feb 2025 08:21:56 -0500
Subject: [PATCH] [libc++] Guard include of <features.h> with __has_include
 (#127691)

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

(cherry picked from commit 2c8b1248513624e89b510397224f0f405116f3d3)
---
 libcxx/include/__configuration/platform.h | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

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__



More information about the llvm-branch-commits mailing list