Skip to content

[Clang][AArch64] Define x86_64 macros for ARM64EC targets #65420

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions clang/lib/Basic/Targets/AArch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,18 @@ void AArch64TargetInfo::getTargetDefinesARMV94A(const LangOptions &Opts,
void AArch64TargetInfo::getTargetDefines(const LangOptions &Opts,
MacroBuilder &Builder) const {
// Target identification.
Builder.defineMacro("__aarch64__");
if (getTriple().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__");
Builder.defineMacro("__amd64");
Builder.defineMacro("__x86_64");
Builder.defineMacro("__x86_64__");
Builder.defineMacro("__arm64ec__");
} else {
Builder.defineMacro("__aarch64__");
}

// Inline assembly supports AArch64 flag outputs.
Builder.defineMacro("__GCC_ASM_FLAG_OUTPUTS__");

Expand Down Expand Up @@ -1466,7 +1477,13 @@ MicrosoftARM64TargetInfo::MicrosoftARM64TargetInfo(const llvm::Triple &Triple,
void MicrosoftARM64TargetInfo::getTargetDefines(const LangOptions &Opts,
MacroBuilder &Builder) const {
WindowsARM64TargetInfo::getTargetDefines(Opts, Builder);
Builder.defineMacro("_M_ARM64", "1");
if (getTriple().isWindowsArm64EC()) {
Builder.defineMacro("_M_X64", "100");
Builder.defineMacro("_M_AMD64", "100");
Builder.defineMacro("_M_ARM64EC", "1");
} else {
Builder.defineMacro("_M_ARM64", "1");
}
}

TargetInfo::CallingConvKind
Expand Down
30 changes: 30 additions & 0 deletions clang/test/Preprocessor/predefined-win-macros.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,19 @@
// CHECK-ARM64-WIN: #define _WIN32 1
// CHECK-ARM64-WIN: #define _WIN64 1

// RUN: %clang_cc1 -triple arm64ec-windows %s -E -dM -o - \
// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-ARM64EC-WIN

// CHECK-ARM64EC-WIN-NOT: #define WIN32 1
// CHECK-ARM64EC-WIN-NOT: #define WIN64 1
// CHECK-ARM64EC-WIN-NOT: #define WINNT 1
// CHECK-ARM64EC-WIN-NOT: #define _M_ARM64 1
// CHECK-ARM64EC-WIN: #define _M_AMD64 100
// CHECK-ARM64EC-WIN: #define _M_ARM64EC 1
// CHECK-ARM64EC-WIN: #define _M_X64 100
// CHECK-ARM64EC-WIN: #define _WIN32 1
// CHECK-ARM64EC-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

Expand Down Expand Up @@ -131,3 +144,20 @@
// CHECK-ARM64-MINGW: #define _WIN64 1
// CHECK-ARM64-MINGW: #define __GCC_ASM_FLAG_OUTPUTS__ 1
// CHECK-ARM64-MINGW: #define __aarch64__ 1

// RUN: %clang_cc1 -triple arm64ec-windows-gnu %s -E -dM -o - \
// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-ARM64EC-MINGW

// CHECK-ARM64EC-MINGW-NOT: #define _M_ARM64EC 1
// CHECK-ARM64EC-MINGW: #define WIN32 1
// CHECK-ARM64EC-MINGW: #define WIN64 1
// CHECK-ARM64EC-MINGW: #define WINNT 1
// CHECK-ARM64EC-MINGW: #define _WIN32 1
// CHECK-ARM64EC-MINGW: #define _WIN64 1
// CHECK-ARM64EC-MINGW: #define __GCC_ASM_FLAG_OUTPUTS__ 1
// CHECK-ARM64EC-MINGW-NOT: #define __aarch64__ 1
// CHECK-ARM64EC-MINGW: #define __amd64 1
// CHECK-ARM64EC-MINGW: #define __amd64__ 1
// CHECK-ARM64EC-MINGW: #define __arm64ec__ 1
// CHECK-ARM64EC-MINGW: #define __x86_64 1
// CHECK-ARM64EC-MINGW: #define __x86_64__ 1