[PATCH] D136712: Define _GNU_SOURCE for arm baremetal in C++ mode.

Manoj Gupta via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 25 13:12:35 PDT 2022


manojgupta created this revision.
manojgupta added reviewers: abidh, tomhughes.
Herald added subscribers: kristof.beyls, ki.stfu, dschuff.
Herald added a project: All.
manojgupta requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This matches other C++ drivers e.g. Linux that define
_GNU_SOURCE. This lets clang compiler more code by default
without explicitly passing _GNU_SOURCE on command line.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D136712

Files:
  clang/lib/Basic/Targets/ARM.cpp
  clang/test/Driver/arm-baremetal-defines.cpp


Index: clang/test/Driver/arm-baremetal-defines.cpp
===================================================================
--- /dev/null
+++ clang/test/Driver/arm-baremetal-defines.cpp
@@ -0,0 +1,13 @@
+// RUN: %clangxx --target=arm-none-eabi -march=armv7-m %s -emit-llvm -S -c -o - 2>&1 | FileCheck %s
+
+// ECHO: {{.*}} "-cc1" {{.*}}mipsel-nacl-defines.c
+
+// CHECK: __ELF__defined
+#ifdef __ELF__
+void __ELF__defined() {}
+#endif
+
+// CHECK: _GNU_SOURCEdefined
+#ifdef _GNU_SOURCE
+void _GNU_SOURCEdefined() {}
+#endif
Index: clang/lib/Basic/Targets/ARM.cpp
===================================================================
--- clang/lib/Basic/Targets/ARM.cpp
+++ clang/lib/Basic/Targets/ARM.cpp
@@ -692,8 +692,11 @@
   // For bare-metal none-eabi.
   if (getTriple().getOS() == llvm::Triple::UnknownOS &&
       (getTriple().getEnvironment() == llvm::Triple::EABI ||
-       getTriple().getEnvironment() == llvm::Triple::EABIHF))
+       getTriple().getEnvironment() == llvm::Triple::EABIHF)) {
     Builder.defineMacro("__ELF__");
+    if (Opts.CPlusPlus)
+      Builder.defineMacro("_GNU_SOURCE");
+  }
 
   // Target properties.
   Builder.defineMacro("__REGISTER_PREFIX__", "");


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D136712.470601.patch
Type: text/x-patch
Size: 1188 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221025/177fbf5c/attachment.bin>


More information about the cfe-commits mailing list