llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: quic-k <details> <summary>Changes</summary> picolibc guards GNU-extension locale functions (e.g. strtold_l) behind __GNU_VISIBLE, which is only enabled when _GNU_SOURCE is defined. Without it, building libcxx against picolibc fails because these functions are undeclared. Add _GNU_SOURCE automatically in HexagonToolChain::addClangTargetOptions when --cstdlib=picolibc is used and the driver is in C++ mode (CCCIsCXX) --- Full diff: https://github.com/llvm/llvm-project/pull/201599.diff 2 Files Affected: - (modified) clang/lib/Driver/ToolChains/Hexagon.cpp (+7) - (modified) clang/test/Driver/hexagon-toolchain-picolibc.c (+12) ``````````diff diff --git a/clang/lib/Driver/ToolChains/Hexagon.cpp b/clang/lib/Driver/ToolChains/Hexagon.cpp index ce3fd5110953a..b28da09d83a75 100644 --- a/clang/lib/Driver/ToolChains/Hexagon.cpp +++ b/clang/lib/Driver/ToolChains/Hexagon.cpp @@ -815,6 +815,13 @@ void HexagonToolChain::addClangTargetOptions(const ArgList &DriverArgs, CC1Args.push_back("-mllvm"); CC1Args.push_back("-hexagon-autohvx"); } + + // picolibc guards GNU-extension functions (e.g. strtold_l) with __GNU_VISIBLE + // which requires _GNU_SOURCE. Define it automatically for C++ compilations + // so that building libcxx against picolibc works without -D_GNU_SOURCE. + if (GetCStdlibType(DriverArgs) == ToolChain::CST_Picolibc && + getDriver().CCCIsCXX()) + CC1Args.push_back("-D_GNU_SOURCE"); } void HexagonToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs, diff --git a/clang/test/Driver/hexagon-toolchain-picolibc.c b/clang/test/Driver/hexagon-toolchain-picolibc.c index 8282a4da81636..4087d66e08f17 100644 --- a/clang/test/Driver/hexagon-toolchain-picolibc.c +++ b/clang/test/Driver/hexagon-toolchain-picolibc.c @@ -236,3 +236,15 @@ // RUN: -mcpu=hexagonv68 -G0 -### %s 2>&1 | FileCheck -check-prefix=CHECK-H2-LIBPATHS-G0 %s // CHECK-H2-LIBPATHS-G0: "-L{{.*}}{{/|\\\\}}Inputs{{/|\\\\}}hexagon_tree{{/|\\\\}}Tools{{/|\\\\}}bin{{/|\\\\}}..{{/|\\\\}}target{{/|\\\\}}picolibc{{/|\\\\}}hexagon-unknown-h2-elf{{/|\\\\}}lib{{/|\\\\}}v68{{/|\\\\}}G0" // CHECK-H2-LIBPATHS-G0: "-L{{.*}}{{/|\\\\}}Inputs{{/|\\\\}}hexagon_tree{{/|\\\\}}Tools{{/|\\\\}}bin{{/|\\\\}}..{{/|\\\\}}target{{/|\\\\}}picolibc{{/|\\\\}}hexagon-unknown-h2-elf{{/|\\\\}}lib{{/|\\\\}}v68" + +// ----------------------------------------------------------------------------- +// picolibc: _GNU_SOURCE is defined automatically for C++ (needed for strtold_l etc.) +// ----------------------------------------------------------------------------- +// RUN: %clangxx --target=hexagon-h2-elf --cstdlib=picolibc -### %s 2>&1 | FileCheck %s --check-prefix=CHECK-GNU-SOURCE +// CHECK-GNU-SOURCE: "-D_GNU_SOURCE" +// +// RUN: %clang --target=hexagon-h2-elf --cstdlib=picolibc -### %s 2>&1 | FileCheck %s --check-prefix=CHECK-C-NO-GNU-SOURCE +// CHECK-C-NO-GNU-SOURCE-NOT: "-D_GNU_SOURCE" +// +// RUN: %clang --target=hexagon-h2-elf -### %s 2>&1 | FileCheck %s --check-prefix=CHECK-NO-PICOLIBC +// CHECK-NO-PICOLIBC-NOT: "-D_GNU_SOURCE" `````````` </details> https://github.com/llvm/llvm-project/pull/201599 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
