Index: lib/Basic/Targets.h =================================================================== --- lib/Basic/Targets.h +++ lib/Basic/Targets.h @@ -40,7 +40,7 @@ bool Tuning = true); LLVM_LIBRARY_VISIBILITY -void addMinGWDefines(const clang::LangOptions &Opts, +void addMinGWDefines(const llvm::Triple &Triple, const clang::LangOptions &Opts, clang::MacroBuilder &Builder); LLVM_LIBRARY_VISIBILITY Index: lib/Basic/Targets.cpp =================================================================== --- lib/Basic/Targets.cpp +++ lib/Basic/Targets.cpp @@ -97,7 +97,14 @@ } } -void addMinGWDefines(const LangOptions &Opts, MacroBuilder &Builder) { +void addMinGWDefines(const llvm::Triple &Triple, const LangOptions &Opts, + MacroBuilder &Builder) { + DefineStd(Builder, "WIN32", Opts); + DefineStd(Builder, "WINNT", Opts); + if (Triple.isArch64Bit()) { + DefineStd(Builder, "WIN64", Opts); + Builder.defineMacro("__MINGW64__"); + } Builder.defineMacro("__MSVCRT__"); Builder.defineMacro("__MINGW32__"); addCygMingDefines(Opts, Builder); Index: lib/Basic/Targets/AArch64.h =================================================================== --- lib/Basic/Targets/AArch64.h +++ lib/Basic/Targets/AArch64.h @@ -122,9 +122,6 @@ : public WindowsARM64TargetInfo { public: MinGWARM64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts); - - void getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const override; }; class LLVM_LIBRARY_VISIBILITY AArch64beTargetInfo : public AArch64TargetInfo { Index: lib/Basic/Targets/AArch64.cpp =================================================================== --- lib/Basic/Targets/AArch64.cpp +++ lib/Basic/Targets/AArch64.cpp @@ -474,8 +474,6 @@ void MicrosoftARM64TargetInfo::getVisualStudioDefines( const LangOptions &Opts, MacroBuilder &Builder) const { WindowsTargetInfo::getVisualStudioDefines(Opts, Builder); - Builder.defineMacro("_WIN32", "1"); - Builder.defineMacro("_WIN64", "1"); Builder.defineMacro("_M_ARM64", "1"); } @@ -491,17 +489,6 @@ TheCXXABI.set(TargetCXXABI::GenericAArch64); } -void MinGWARM64TargetInfo::getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const { - WindowsTargetInfo::getTargetDefines(Opts, Builder); - Builder.defineMacro("_WIN32", "1"); - Builder.defineMacro("_WIN64", "1"); - Builder.defineMacro("WIN32", "1"); - Builder.defineMacro("WIN64", "1"); - addMinGWDefines(Opts, Builder); -} - - DarwinAArch64TargetInfo::DarwinAArch64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) : DarwinTargetInfo(Triple, Opts) { Index: lib/Basic/Targets/ARM.cpp =================================================================== --- lib/Basic/Targets/ARM.cpp +++ lib/Basic/Targets/ARM.cpp @@ -999,11 +999,8 @@ void MinGWARMTargetInfo::getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const { WindowsARMTargetInfo::getTargetDefines(Opts, Builder); - DefineStd(Builder, "WIN32", Opts); - DefineStd(Builder, "WINNT", Opts); Builder.defineMacro("_ARM_"); Builder.defineMacro("__ARM_DWARF_EH__"); - addMinGWDefines(Opts, Builder); } CygwinARMTargetInfo::CygwinARMTargetInfo(const llvm::Triple &Triple, Index: lib/Basic/Targets/OSTargets.h =================================================================== --- lib/Basic/Targets/OSTargets.h +++ lib/Basic/Targets/OSTargets.h @@ -572,6 +572,11 @@ void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override { Builder.defineMacro("_WIN32"); + if (Triple.isArch64Bit()) + Builder.defineMacro("_WIN64"); + if (Triple.isWindowsGNUEnvironment()) + addMinGWDefines(Triple, Opts, Builder); + } void getVisualStudioDefines(const LangOptions &Opts, MacroBuilder &Builder) const { Index: lib/Basic/Targets/X86.h =================================================================== --- lib/Basic/Targets/X86.h +++ lib/Basic/Targets/X86.h @@ -410,11 +410,6 @@ ? "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32" : "e-m:e-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32"); } - - void getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const override { - WindowsTargetInfo::getTargetDefines(Opts, Builder); - } }; // x86-32 Windows Visual Studio target @@ -451,10 +446,7 @@ void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override { WindowsX86_32TargetInfo::getTargetDefines(Opts, Builder); - DefineStd(Builder, "WIN32", Opts); - DefineStd(Builder, "WINNT", Opts); Builder.defineMacro("_X86_"); - addMinGWDefines(Opts, Builder); } }; @@ -658,12 +650,6 @@ IntPtrType = SignedLongLong; } - void getTargetDefines(const LangOptions &Opts, - MacroBuilder &Builder) const override { - WindowsTargetInfo::getTargetDefines(Opts, Builder); - Builder.defineMacro("_WIN64"); - } - BuiltinVaListKind getBuiltinVaListKind() const override { return TargetInfo::CharPtrBuiltinVaList; } @@ -726,9 +712,6 @@ void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override { WindowsX86_64TargetInfo::getTargetDefines(Opts, Builder); - DefineStd(Builder, "WIN64", Opts); - Builder.defineMacro("__MINGW64__"); - addMinGWDefines(Opts, Builder); // GCC defines this macro when it is using __gxx_personality_seh0. if (!Opts.SjLjExceptions) Index: test/Preprocessor/predefined-macros.c =================================================================== --- test/Preprocessor/predefined-macros.c +++ test/Preprocessor/predefined-macros.c @@ -193,19 +193,77 @@ // MSCOPE:#define __OPENCL_MEMORY_SCOPE_WORK_GROUP 1 // MSCOPE:#define __OPENCL_MEMORY_SCOPE_WORK_ITEM 0 +// RUN: %clang_cc1 -triple i386-windows %s -E -dM -o - \ +// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-X86-WIN + +// CHECK-X86-WIN-NOT: #define WIN32 1 +// CHECK-X86-WIN-NOT: #define WIN64 1 +// CHECK-X86-WIN-NOT: #define WINNT 1 +// CHECK-X86-WIN: #define _WIN32 1 +// CHECK-X86-WIN-NOT: #define _WIN64 1 + +// RUN: %clang_cc1 -triple thumbv7-windows %s -E -dM -o - \ +// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-ARM-WIN + +// CHECK-ARM-WIN-NOT: #define WIN32 1 +// CHECK-ARM-WIN-NOT: #define WIN64 1 +// CHECK-ARM-WIN-NOT: #define WINNT 1 +// CHECK-ARM-WIN: #define _WIN32 1 +// CHECK-ARM-WIN-NOT: #define _WIN64 1 + +// RUN: %clang_cc1 -triple x86_64-windows %s -E -dM -o - \ +// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-AMD64-WIN + +// CHECK-AMD64-WIN-NOT: #define WIN32 1 +// CHECK-AMD64-WIN-NOT: #define WIN64 1 +// CHECK-AMD64-WIN-NOT: #define WINNT 1 +// CHECK-AMD64-WIN: #define _WIN32 1 +// CHECK-AMD64-WIN: #define _WIN64 1 + // RUN: %clang_cc1 -triple aarch64-windows %s -E -dM -o - \ // RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-ARM64-WIN +// CHECK-ARM64-WIN-NOT: #define WIN32 1 +// CHECK-ARM64-WIN-NOT: #define WIN64 1 +// CHECK-ARM64-WIN-NOT: #define WINNT 1 // CHECK-ARM64-WIN: #define _M_ARM64 1 // CHECK-ARM64-WIN: #define _WIN32 1 // CHECK-ARM64-WIN: #define _WIN64 1 +// RUN: %clang_cc1 -triple i686-windows-gnu %s -E -dM -o - \ +// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-X86-MINGW + +// CHECK-X86-MINGW: #define WIN32 1 +// CHECK-X86-MINGW-NOT: #define WIN64 1 +// CHECK-X86-MINGW: #define WINNT 1 +// CHECK-X86-MINGW: #define _WIN32 1 +// CHECK-X86-MINGW-NOT: #define _WIN64 1 + +// RUN: %clang_cc1 -triple thumbv7-windows-gnu %s -E -dM -o - \ +// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-ARM-MINGW + +// CHECK-ARM-MINGW: #define WIN32 1 +// CHECK-ARM-MINGW-NOT: #define WIN64 1 +// CHECK-ARM-MINGW: #define WINNT 1 +// CHECK-ARM-MINGW: #define _WIN32 1 +// CHECK-ARM-MINGW-NOT: #define _WIN64 1 + +// RUN: %clang_cc1 -triple x86_64-windows-gnu %s -E -dM -o - \ +// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-AMD64-MINGW + +// CHECK-AMD64-MINGW: #define WIN32 1 +// CHECK-AMD64-MINGW: #define WIN64 1 +// CHECK-AMD64-MINGW: #define WINNT 1 +// CHECK-AMD64-MINGW: #define _WIN32 1 +// CHECK-AMD64-MINGW: #define _WIN64 1 + // RUN: %clang_cc1 -triple aarch64-windows-gnu %s -E -dM -o - \ // RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-ARM64-MINGW // CHECK-ARM64-MINGW-NOT: #define _M_ARM64 1 // CHECK-ARM64-MINGW: #define WIN32 1 // CHECK-ARM64-MINGW: #define WIN64 1 +// CHECK-ARM64-MINGW: #define WINNT 1 // CHECK-ARM64-MINGW: #define _WIN32 1 // CHECK-ARM64-MINGW: #define _WIN64 1 // CHECK-ARM64-MINGW: #define __aarch64__ 1