[Basic] Define __declspec for cygwin

Cygwin (and MinGW) targets define __declspec to __attribute__ unless
-fms-extensions is specified.  It turns out that cygwin headers rely on
the existence of this macro.

llvm-svn: 238394
This commit is contained in:
David Majnemer 2015-05-28 04:36:18 +00:00
parent 424a5dbc73
commit ae1ed0edfe
2 changed files with 19 additions and 5 deletions

View File

@ -3596,11 +3596,8 @@ public:
}; };
} // end anonymous namespace } // end anonymous namespace
static void addMinGWDefines(const LangOptions &Opts, MacroBuilder &Builder) { static void addCygMingDefines(const LangOptions &Opts, MacroBuilder &Builder) {
Builder.defineMacro("__MSVCRT__"); // Mingw and cygwin define __declspec(a) to __attribute__((a)). Clang supports
Builder.defineMacro("__MINGW32__");
// Mingw defines __declspec(a) to __attribute__((a)). Clang supports
// __declspec natively under -fms-extensions, but we define a no-op __declspec // __declspec natively under -fms-extensions, but we define a no-op __declspec
// macro anyway for pre-processor compatibility. // macro anyway for pre-processor compatibility.
if (Opts.MicrosoftExt) if (Opts.MicrosoftExt)
@ -3623,6 +3620,12 @@ static void addMinGWDefines(const LangOptions &Opts, MacroBuilder &Builder) {
} }
} }
static void addMinGWDefines(const LangOptions &Opts, MacroBuilder &Builder) {
Builder.defineMacro("__MSVCRT__");
Builder.defineMacro("__MINGW32__");
addCygMingDefines(Opts, Builder);
}
namespace { namespace {
// x86-32 MinGW target // x86-32 MinGW target
class MinGWX86_32TargetInfo : public WindowsX86_32TargetInfo { class MinGWX86_32TargetInfo : public WindowsX86_32TargetInfo {
@ -3655,6 +3658,7 @@ public:
Builder.defineMacro("_X86_"); Builder.defineMacro("_X86_");
Builder.defineMacro("__CYGWIN__"); Builder.defineMacro("__CYGWIN__");
Builder.defineMacro("__CYGWIN32__"); Builder.defineMacro("__CYGWIN32__");
addCygMingDefines(Opts, Builder);
DefineStd(Builder, "unix", Opts); DefineStd(Builder, "unix", Opts);
if (Opts.CPlusPlus) if (Opts.CPlusPlus)
Builder.defineMacro("_GNU_SOURCE"); Builder.defineMacro("_GNU_SOURCE");

View File

@ -2793,6 +2793,12 @@
// RUN: %clang_cc1 -E -dM -ffreestanding -triple=i386-netbsd6 -target-feature +sse2 < /dev/null | FileCheck -check-prefix I386-NETBSD6-SSE %s // RUN: %clang_cc1 -E -dM -ffreestanding -triple=i386-netbsd6 -target-feature +sse2 < /dev/null | FileCheck -check-prefix I386-NETBSD6-SSE %s
// I386-NETBSD6-SSE:#define __FLT_EVAL_METHOD__ 1 // I386-NETBSD6-SSE:#define __FLT_EVAL_METHOD__ 1
// RUN: %clang_cc1 -E -dM -triple=i686-pc-mingw32 < /dev/null | FileCheck -check-prefix I386-DECLSPEC %s
// RUN: %clang_cc1 -E -dM -fms-extensions -triple=i686-pc-mingw32 < /dev/null | FileCheck -check-prefix I386-DECLSPEC %s
// RUN: %clang_cc1 -E -dM -triple=i686-unknown-cygwin < /dev/null | FileCheck -check-prefix I386-DECLSPEC %s
// RUN: %clang_cc1 -E -dM -fms-extensions -triple=i686-unknown-cygwin < /dev/null | FileCheck -check-prefix I386-DECLSPEC %s
// I386-DECLSPEC: #define __declspec
// //
// RUN: %clang_cc1 -E -dM -ffreestanding -triple=mips-none-none < /dev/null | FileCheck -check-prefix MIPS32BE %s // RUN: %clang_cc1 -E -dM -ffreestanding -triple=mips-none-none < /dev/null | FileCheck -check-prefix MIPS32BE %s
// //
@ -8346,6 +8352,10 @@
// PS4:#define __x86_64 1 // PS4:#define __x86_64 1
// PS4:#define __x86_64__ 1 // PS4:#define __x86_64__ 1
// //
// RUN: %clang_cc1 -E -dM -triple=x86_64-pc-mingw32 < /dev/null | FileCheck -check-prefix X86-64-DECLSPEC %s
// RUN: %clang_cc1 -E -dM -fms-extensions -triple=x86_64-unknown-mingw32 < /dev/null | FileCheck -check-prefix X86-64-DECLSPEC %s
// X86-64-DECLSPEC: #define __declspec
//
// RUN: %clang_cc1 -E -dM -ffreestanding -triple=sparc64-none-none < /dev/null | FileCheck -check-prefix SPARCV9 %s // RUN: %clang_cc1 -E -dM -ffreestanding -triple=sparc64-none-none < /dev/null | FileCheck -check-prefix SPARCV9 %s
// SPARCV9:#define __INT64_TYPE__ long int // SPARCV9:#define __INT64_TYPE__ long int
// SPARCV9:#define __INTMAX_C_SUFFIX__ L // SPARCV9:#define __INTMAX_C_SUFFIX__ L