Skip to content

[flang] Add aarch64 processor defines #142606

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 2 commits into from
Jun 4, 2025
Merged

Conversation

DavidTruby
Copy link
Member

This patch adds aarch64 specific processor defines when targeting
aarch64, similar to the ones for ppc64 and x86_64

This patch adds aarch64 specific processor defines when targeting
aarch64, similar to the ones for ppc64 and x86_64
@llvmbot llvmbot added flang:driver flang Flang issues not falling into any other category labels Jun 3, 2025
@DavidTruby DavidTruby requested review from tblah and pawosm-arm June 3, 2025 13:33
@llvmbot
Copy link
Member

llvmbot commented Jun 3, 2025

@llvm/pr-subscribers-flang-driver

Author: David Truby (DavidTruby)

Changes

This patch adds aarch64 specific processor defines when targeting
aarch64, similar to the ones for ppc64 and x86_64


Full diff: https://github.com/llvm/llvm-project/pull/142606.diff

2 Files Affected:

  • (modified) flang/lib/Frontend/CompilerInvocation.cpp (+4)
  • (added) flang/test/Driver/predefined-macros-aarch64.f90 (+16)
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp
index 90a002929eff0..89aaee9f13853 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -1656,6 +1656,10 @@ void CompilerInvocation::setDefaultPredefinitions() {
       fortranOptions.predefinitions.emplace_back("__64BIT__", "1");
     }
     break;
+  case llvm::Triple::ArchType::aarch64:
+    fortranOptions.predefinitions.emplace_back("__aarch64__", "1");
+    fortranOptions.predefinitions.emplace_back("__aarch64", "1");
+    break;
   }
 }
 
diff --git a/flang/test/Driver/predefined-macros-aarch64.f90 b/flang/test/Driver/predefined-macros-aarch64.f90
new file mode 100644
index 0000000000000..ff49c7e0cb85a
--- /dev/null
+++ b/flang/test/Driver/predefined-macros-aarch64.f90
@@ -0,0 +1,16 @@
+! Test predefined macro for 64 bit X86 architecture
+
+! REQUIRES: aarch64-registered-target
+
+! RUN: %flang_fc1 -triple aarch64-unknown-linux-gnu -cpp -E %s | FileCheck %s
+
+! CHECK: integer :: var1 = 1
+! CHECK: integer :: var2 = 1
+
+#if __aarch64__
+  integer :: var1 = __aarch64__
+#endif
+#if __aarch64
+  integer :: var2 = __aarch64
+#endif
+end program

@DavidTruby DavidTruby requested a review from kkwli June 3, 2025 13:33
@pawosm-arm pawosm-arm self-requested a review June 4, 2025 09:21
Copy link
Contributor

@tblah tblah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@DavidTruby DavidTruby merged commit b59c888 into llvm:main Jun 4, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:driver flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants