llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Hussam Alhassan (hussam-alhassan) <details> <summary>Changes</summary> Set the _GNU_SOURCE macro when compiling for aarch64-none-elf in C++ mode to enable libc++ headers to use GNU interfaces. This matches ARM.cpp when compiling or arm-none-eabi. --- Full diff: https://github.com/llvm/llvm-project/pull/225071.diff 2 Files Affected: - (modified) clang/lib/Basic/Targets/AArch64.cpp (+9-2) - (modified) clang/test/Preprocessor/init-aarch64.c (+3) ``````````diff diff --git a/clang/lib/Basic/Targets/AArch64.cpp b/clang/lib/Basic/Targets/AArch64.cpp index a4841514be35e..9aac476a078f5 100644 --- a/clang/lib/Basic/Targets/AArch64.cpp +++ b/clang/lib/Basic/Targets/AArch64.cpp @@ -402,8 +402,9 @@ void AArch64TargetInfo::getTargetDefinesARMV97A(const LangOptions &Opts, void AArch64TargetInfo::getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const { + const llvm::Triple &T = getTriple(); // Target identification. - if (getTriple().isWindowsArm64EC()) { + if (T.isWindowsArm64EC()) { // Define the same set of macros as would be defined on x86_64 to ensure that // ARM64EC datatype layouts match those of x86_64 compiled code Builder.defineMacro("__amd64__"); @@ -415,7 +416,13 @@ void AArch64TargetInfo::getTargetDefines(const LangOptions &Opts, Builder.defineMacro("__aarch64__"); } - if (getTriple().isLFI()) + // For bare-metal none-elf. + if (T.getOS() == llvm::Triple::UnknownOS && T.getEnvironmentName() == "elf" && + Opts.CPlusPlus) { + Builder.defineMacro("_GNU_SOURCE"); + } + + if (T.isLFI()) Builder.defineMacro("__LFI__"); // Inline assembly supports AArch64 flag outputs. diff --git a/clang/test/Preprocessor/init-aarch64.c b/clang/test/Preprocessor/init-aarch64.c index 44b92ea2331b0..51aabb40242c2 100644 --- a/clang/test/Preprocessor/init-aarch64.c +++ b/clang/test/Preprocessor/init-aarch64.c @@ -1170,3 +1170,6 @@ // CMODEL_TINY: #define __AARCH64_CMODEL_TINY__ 1 // CMODEL_SMALL: #define __AARCH64_CMODEL_SMALL__ 1 // CMODEL_LARGE: #define __AARCH64_CMODEL_LARGE__ 1 + +// RUN: %clang_cc1 -x c++ -E -dM -ffreestanding -triple=aarch64-none-elf < /dev/null | FileCheck -match-full-lines -check-prefix AARCH64-NONE-ELF-CXX %s +// AARCH64-NONE-ELF-CXX: #define _GNU_SOURCE 1 `````````` </details> https://github.com/llvm/llvm-project/pull/225071 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
