From 2b003fd2766914133fa7418e1b368ca171ac4205 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Wed, 21 Apr 2010 05:52:38 +0000 Subject: [PATCH] Sink the _GNU_SOURCE definition down into the target configuration, and only define it where we know we need it---Linux and Cygwin. Thanks to Chris for the prodding. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@101989 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Basic/Targets.cpp | 4 ++++ lib/Frontend/InitPreprocessor.cpp | 24 ------------------------ 2 files changed, 4 insertions(+), 24 deletions(-) diff --git a/lib/Basic/Targets.cpp b/lib/Basic/Targets.cpp index 1b80527aca..b94f55bdfd 100644 --- a/lib/Basic/Targets.cpp +++ b/lib/Basic/Targets.cpp @@ -219,6 +219,8 @@ protected: Builder.defineMacro("__ELF__"); if (Opts.POSIXThreads) Builder.defineMacro("_REENTRANT"); + if (Opts.CPlusPlus) + Builder.defineMacro("_GNU_SOURCE"); } public: LinuxTargetInfo(const std::string& triple) @@ -1221,6 +1223,8 @@ public: Builder.defineMacro("__CYGWIN__"); Builder.defineMacro("__CYGWIN32__"); DefineStd(Builder, "unix", Opts); + if (Opts.CPlusPlus) + Builder.defineMacro("_GNU_SOURCE"); } }; } // end anonymous namespace diff --git a/lib/Frontend/InitPreprocessor.cpp b/lib/Frontend/InitPreprocessor.cpp index aacae49540..ea0f8c0877 100644 --- a/lib/Frontend/InitPreprocessor.cpp +++ b/lib/Frontend/InitPreprocessor.cpp @@ -294,30 +294,6 @@ static void InitializePredefinedMacros(const TargetInfo &TI, // C++ translation unit. Builder.defineMacro("__cplusplus", "199711L"); Builder.defineMacro("__private_extern__", "extern"); - - // Define _GNU_SOURCE on platforms where we expect to use glibc. - switch (TI.getTriple().getOS()) { - case llvm::Triple::Cygwin: - case llvm::Triple::MinGW64: - case llvm::Triple::MinGW32: - case llvm::Triple::Linux: - case llvm::Triple::Solaris: - case llvm::Triple::AuroraUX: - Builder.defineMacro("_GNU_SOURCE"); - break; - - case llvm::Triple::Darwin: - case llvm::Triple::DragonFly: - case llvm::Triple::FreeBSD: - case llvm::Triple::UnknownOS: - case llvm::Triple::Lv2: - case llvm::Triple::NetBSD: - case llvm::Triple::OpenBSD: - case llvm::Triple::Psp: - case llvm::Triple::Win32: - case llvm::Triple::Haiku: - break; - } } if (LangOpts.Microsoft) { -- 2.40.0