[clang] 25ec96d - [Clang][Driver] Recognize the AIX OBJECT_MODE environment setting
David Tenty via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 9 12:15:37 PDT 2020
Author: David Tenty
Date: 2020-07-09T15:15:30-04:00
New Revision: 25ec96d91a3a5326a403496fa5532ff0bdb6a15b
URL: https://github.com/llvm/llvm-project/commit/25ec96d91a3a5326a403496fa5532ff0bdb6a15b
DIFF: https://github.com/llvm/llvm-project/commit/25ec96d91a3a5326a403496fa5532ff0bdb6a15b.diff
LOG: [Clang][Driver] Recognize the AIX OBJECT_MODE environment setting
Summary:
AIX uses an environment variable called OBJECT_MODE to indicate to
utilities in the toolchain whether they should be operating in 32-bit or
64-bit mode. This patch makes the clang driver recognize the current
OBJECT_MODE setting when we are operating with an AIX target and adds a
custom diagnostic for invalid settings.
For more details about OBJECT_MODE on AIX see:
https://www.ibm.com/support/knowledgecenter/SSGH2K_13.1.3/com.ibm.xlc1313.aix.doc/compiler_ref/tusetenv1.html
https://www.ibm.com/support/knowledgecenter/SSGH2K_13.1.3/com.ibm.xlc1313.aix.doc/compiler_ref/opt_3264.html
Reviewers: stevewan, hubert.reinterpretcast, ShuhongL, jasonliu
Reviewed By: hubert.reinterpretcast, jasonliu
Subscribers: jasonliu, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D82476
Added:
clang/test/Driver/aix-object-mode.c
Modified:
clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/lib/Driver/Driver.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index dcb3b96cd057..baf01d853233 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -509,4 +509,6 @@ def warn_drv_libstdcxx_not_found : Warning<
InGroup<DiagGroup<"stdlibcxx-not-found">>;
def err_drv_cannot_mix_options : Error<"cannot specify '%1' along with '%0'">;
+
+def err_drv_invalid_object_mode : Error<"OBJECT_MODE setting %0 is not recognized and is not a valid setting.">;
}
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 596e694760d0..ece8222dcf24 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -475,6 +475,26 @@ static llvm::Triple computeTargetTriple(const Driver &D,
Target.getOS() == llvm::Triple::Minix)
return Target;
+ // On AIX, the env OBJECT_MODE may affect the resulting arch variant.
+ if (Target.isOSAIX()) {
+ if (Optional<std::string> ObjectModeValue =
+ llvm::sys::Process::GetEnv("OBJECT_MODE")) {
+ StringRef ObjectMode = *ObjectModeValue;
+ llvm::Triple::ArchType AT = llvm::Triple::UnknownArch;
+
+ if (ObjectMode.equals("64")) {
+ AT = Target.get64BitArchVariant().getArch();
+ } else if (ObjectMode.equals("32")) {
+ AT = Target.get32BitArchVariant().getArch();
+ } else {
+ D.Diag(diag::err_drv_invalid_object_mode) << ObjectMode;
+ }
+
+ if (AT != llvm::Triple::UnknownArch && AT != Target.getArch())
+ Target.setArch(AT);
+ }
+ }
+
// Handle pseudo-target flags '-m64', '-mx32', '-m32' and '-m16'.
Arg *A = Args.getLastArg(options::OPT_m64, options::OPT_mx32,
options::OPT_m32, options::OPT_m16);
diff --git a/clang/test/Driver/aix-object-mode.c b/clang/test/Driver/aix-object-mode.c
new file mode 100644
index 000000000000..a4bc79a4b41d
--- /dev/null
+++ b/clang/test/Driver/aix-object-mode.c
@@ -0,0 +1,22 @@
+// Check that setting an OBJECT_MODE converts the AIX triple to the right variant.
+// RUN: env OBJECT_MODE=64 \
+// RUN: %clang -target powerpc-ibm-aix -print-target-triple | FileCheck -check-prefix=CHECK64 %s
+
+// RUN: env OBJECT_MODE=32 \
+// RUN: %clang -target powerpc64-ibm-aix -print-target-triple | FileCheck -check-prefix=CHECK32 %s
+
+// Command-line options win.
+// RUN: env OBJECT_MODE=64 \
+// RUN: %clang -target powerpc64-ibm-aix -print-target-triple -m32 | FileCheck -check-prefix=CHECK32 %s
+
+// RUN: env OBJECT_MODE=32 \
+// RUN: %clang -target powerpc-ibm-aix -print-target-triple -m64 | FileCheck -check-prefix=CHECK64 %s
+
+// CHECK32: powerpc-ibm-aix
+// CHECK64: powerpc64-ibm-aix
+
+// Emit a diagnostic if there is an invalid mode.
+// RUN: env OBJECT_MODE=31 \
+// RUN: not %clang -target powerpc-ibm-aix 2>&1 | FileCheck -check-prefix=DIAG %s
+
+// DIAG: error: OBJECT_MODE setting 31 is not recognized and is not a valid setting.
More information about the cfe-commits
mailing list