[flang-commits] [clang] [flang] Enable `-m32`, `-maix32` and `-maix64` for Flang on AIX. (PR #136202)
Daniel Chen via flang-commits
flang-commits at lists.llvm.org
Sat Apr 19 16:51:15 PDT 2025
https://github.com/DanielCChen updated https://github.com/llvm/llvm-project/pull/136202
>From ca318afb810504d248c8bedeb13e2f742a446c37 Mon Sep 17 00:00:00 2001
From: Daniel Chen <cdchen at ca.ibm.com>
Date: Thu, 17 Apr 2025 17:06:27 -0400
Subject: [PATCH 1/4] Enable -m32, -maix32 and -maix64 for Flang on AIX.
---
clang/include/clang/Driver/Options.td | 8 +++++---
clang/lib/Driver/Driver.cpp | 15 ++++++++++-----
flang/test/Driver/m32-option.f90 | 14 ++++++++++++++
3 files changed, 29 insertions(+), 8 deletions(-)
create mode 100644 flang/test/Driver/m32-option.f90
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index e9acb20348654..84254dfa43249 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4694,15 +4694,17 @@ def EB : Flag<["-"], "EB">, Alias<mbig_endian>;
def m16 : Flag<["-"], "m16">, Group<m_Group>, Flags<[NoXarchOption]>,
Visibility<[ClangOption, CLOption, DXCOption]>;
def m32 : Flag<["-"], "m32">, Group<m_Group>, Flags<[NoXarchOption]>,
- Visibility<[ClangOption, CLOption, DXCOption]>;
-def maix32 : Flag<["-"], "maix32">, Group<m_Group>, Flags<[NoXarchOption]>;
+ Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>;
+def maix32 : Flag<["-"], "maix32">, Group<m_Group>, Flags<[NoXarchOption]>,
+ Visibility<[FlangOption]>;
def mqdsp6_compat : Flag<["-"], "mqdsp6-compat">, Group<m_Group>,
Flags<[NoXarchOption]>, Visibility<[ClangOption, CC1Option]>,
HelpText<"Enable hexagon-qdsp6 backward compatibility">,
MarshallingInfoFlag<LangOpts<"HexagonQdsp6Compat">>;
def m64 : Flag<["-"], "m64">, Group<m_Group>, Flags<[NoXarchOption]>,
Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>;
-def maix64 : Flag<["-"], "maix64">, Group<m_Group>, Flags<[NoXarchOption]>;
+def maix64 : Flag<["-"], "maix64">, Group<m_Group>, Flags<[NoXarchOption]>,
+ Visibility<[FlangOption]>;
def mx32 : Flag<["-"], "mx32">, Group<m_Group>, Flags<[NoXarchOption]>,
Visibility<[ClangOption, CLOption, DXCOption]>;
def miamcu : Flag<["-"], "miamcu">, Group<m_Group>, Flags<[NoXarchOption]>,
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 90d8e823d1d02..808a18883b079 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -733,11 +733,16 @@ static llvm::Triple computeTargetTriple(const Driver &D,
Target.setEnvironment(llvm::Triple::GNUX32);
} else if (A->getOption().matches(options::OPT_m32) ||
A->getOption().matches(options::OPT_maix32)) {
- AT = Target.get32BitArchVariant().getArch();
- if (Target.getEnvironment() == llvm::Triple::GNUX32)
- Target.setEnvironment(llvm::Triple::GNU);
- else if (Target.getEnvironment() == llvm::Triple::MuslX32)
- Target.setEnvironment(llvm::Triple::Musl);
+ if (D.IsFlangMode() && !Target.isOSAIX() )
+ D.Diag(diag::err_drv_unsupported_opt_for_target)
+ << A->getAsString(Args) << Target.str();
+ else {
+ AT = Target.get32BitArchVariant().getArch();
+ if (Target.getEnvironment() == llvm::Triple::GNUX32)
+ Target.setEnvironment(llvm::Triple::GNU);
+ else if (Target.getEnvironment() == llvm::Triple::MuslX32)
+ Target.setEnvironment(llvm::Triple::Musl);
+ }
} else if (A->getOption().matches(options::OPT_m16) &&
Target.get32BitArchVariant().getArch() == llvm::Triple::x86) {
AT = llvm::Triple::x86;
diff --git a/flang/test/Driver/m32-option.f90 b/flang/test/Driver/m32-option.f90
new file mode 100644
index 0000000000000..722bddfa43739
--- /dev/null
+++ b/flang/test/Driver/m32-option.f90
@@ -0,0 +1,14 @@
+! Check support of -m32.
+! RUN: %flang -target powerpc-ibm-aix -m32 -### - %s 2>&1 | FileCheck -check-prefix=M32 %s
+! RUN: %flang -target powerpc64-ibm-aix -m32 -### - %s 2>&1 | FileCheck -check-prefix=M32 %s
+! RUN: %flang -target powerpc-ibm-aix -maix32 -### - %s 2>&1 | FileCheck -check-prefix=M32 %s
+! RUN: %flang -target powerpc64-ibm-aix -maix32 -### - %s 2>&1 | FileCheck -check-prefix=M32 %s
+! RUN: %flang -target powerpc-ibm-aix -maix64 -### - %s 2>&1 | FileCheck -check-prefix=M64 %s
+! RUN: %flang -target powerpc64-ibm-aix -maix64 -### - %s 2>&1 | FileCheck -check-prefix=M64 %s
+! RUN: not %flang -target powerpc64le-unknown-linux-gnu -m32 -### - %s 2>&1 | FileCheck -check-prefix=M32-ERROR %s
+! RUN: not %flang -target powerpc64le-unknown-linux-gnu -maix32 -### - %s 2>&1 | FileCheck -check-prefix=MAIX32-ERROR %s
+
+! M32: "-triple" "powerpc-ibm-aix{{.*}}"
+! M64: "-triple" "powerpc64-ibm-aix{{.*}}"
+! M32-ERROR: error: unsupported option '-m32' for target 'powerpc64le-unknown-linux-gnu'
+! MAIX32-ERROR: error: unsupported option '-maix32' for target 'powerpc64le-unknown-linux-gnu'
>From 690158f872cc09024510c4916a31a672498b8c51 Mon Sep 17 00:00:00 2001
From: Daniel Chen <cdchen at ca.ibm.com>
Date: Thu, 17 Apr 2025 17:13:42 -0400
Subject: [PATCH 2/4] Minor format change.
---
clang/lib/Driver/Driver.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 808a18883b079..cf10324364606 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -733,7 +733,7 @@ static llvm::Triple computeTargetTriple(const Driver &D,
Target.setEnvironment(llvm::Triple::GNUX32);
} else if (A->getOption().matches(options::OPT_m32) ||
A->getOption().matches(options::OPT_maix32)) {
- if (D.IsFlangMode() && !Target.isOSAIX() )
+ if (D.IsFlangMode() && !Target.isOSAIX())
D.Diag(diag::err_drv_unsupported_opt_for_target)
<< A->getAsString(Args) << Target.str();
else {
>From d11b56a6a46402a5bddf48451be1bc4b45d778cb Mon Sep 17 00:00:00 2001
From: Daniel Chen <cdchen at ca.ibm.com>
Date: Thu, 17 Apr 2025 17:20:49 -0400
Subject: [PATCH 3/4] Minor format change 2.
---
clang/lib/Driver/Driver.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index cf10324364606..6489e387a8b77 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -735,7 +735,7 @@ static llvm::Triple computeTargetTriple(const Driver &D,
A->getOption().matches(options::OPT_maix32)) {
if (D.IsFlangMode() && !Target.isOSAIX())
D.Diag(diag::err_drv_unsupported_opt_for_target)
- << A->getAsString(Args) << Target.str();
+ << A->getAsString(Args) << Target.str();
else {
AT = Target.get32BitArchVariant().getArch();
if (Target.getEnvironment() == llvm::Triple::GNUX32)
>From 14e5929d96d54be5e5a3926204ee8b4f00f1ced8 Mon Sep 17 00:00:00 2001
From: Daniel Chen <cdchen at ca.ibm.com>
Date: Sat, 19 Apr 2025 19:49:10 -0400
Subject: [PATCH 4/4] Fix the format in response to review comments.
---
clang/lib/Driver/Driver.cpp | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 6489e387a8b77..32c7bba7cfae1 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -733,9 +733,10 @@ static llvm::Triple computeTargetTriple(const Driver &D,
Target.setEnvironment(llvm::Triple::GNUX32);
} else if (A->getOption().matches(options::OPT_m32) ||
A->getOption().matches(options::OPT_maix32)) {
- if (D.IsFlangMode() && !Target.isOSAIX())
+ if (D.IsFlangMode() && !Target.isOSAIX()) {
D.Diag(diag::err_drv_unsupported_opt_for_target)
<< A->getAsString(Args) << Target.str();
+ }
else {
AT = Target.get32BitArchVariant().getArch();
if (Target.getEnvironment() == llvm::Triple::GNUX32)
More information about the flang-commits
mailing list