https://github.com/quic-k updated 
https://github.com/llvm/llvm-project/pull/201599

>From 40755a470778dbfe91e92d68e4f6b92a3b81c20e Mon Sep 17 00:00:00 2001
From: Kushal Pal <[email protected]>
Date: Thu, 4 Jun 2026 20:00:00 +0530
Subject: [PATCH] [Clang][Hexagon] Predefine _GNU_SOURCE for C++ compilations

C++ programs using both picolibc and libc++ headers on Hexagon
currently require manually passing -D_GNU_SOURCE on every
compilation.
Picolibc guards GNU-extension locale functions (e.g., strtold_l)
behind __GNU_VISIBLE, which is only enabled when _GNU_SOURCE is
defined.

Follow the same convention as other targets and predefine
_GNU_SOURCE automatically when compiling C++ for Hexagon.

Signed-off-by: Kushal Pal <[email protected]>
---
 clang/lib/Basic/Targets/Hexagon.cpp          | 3 +++
 clang/test/Preprocessor/hexagon-predefines.c | 8 ++++++++
 2 files changed, 11 insertions(+)

diff --git a/clang/lib/Basic/Targets/Hexagon.cpp 
b/clang/lib/Basic/Targets/Hexagon.cpp
index 9bf34e67a03fd..b65c1f4f46e50 100644
--- a/clang/lib/Basic/Targets/Hexagon.cpp
+++ b/clang/lib/Basic/Targets/Hexagon.cpp
@@ -116,6 +116,9 @@ void HexagonTargetInfo::getTargetDefines(const LangOptions 
&Opts,
   Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2");
   Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4");
   Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8");
+
+  if (Opts.CPlusPlus)
+    Builder.defineMacro("_GNU_SOURCE");
 }
 
 bool HexagonTargetInfo::initFeatureMap(
diff --git a/clang/test/Preprocessor/hexagon-predefines.c 
b/clang/test/Preprocessor/hexagon-predefines.c
index cb3e9492ea07e..df27c307c1cb2 100644
--- a/clang/test/Preprocessor/hexagon-predefines.c
+++ b/clang/test/Preprocessor/hexagon-predefines.c
@@ -261,3 +261,11 @@
 // CHECK-H2: #define __h2__ 1
 // CHECK-H2: #define __hexagon__ 1
 // CHECK-H2-NOT: #define __linux__
+
+// RUN: %clang_cc1 -E -dM -triple hexagon-unknown-elf -x c++ %s | FileCheck \
+// RUN: %s -check-prefix CHECK-CXX-GNU
+// CHECK-CXX-GNU: #define _GNU_SOURCE 1
+
+// RUN: %clang_cc1 -E -dM -triple hexagon-unknown-elf %s | FileCheck \
+// RUN: %s -check-prefix CHECK-C-GNU
+// CHECK-C-GNU-NOT: #define _GNU_SOURCE

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to