llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang-driver Author: Rainer Orth (rorth) <details> <summary>Changes</summary> While working on supporting PR #<!-- -->109101 on Linux/sparc64, I was reminded that `clang -m32` still defaults to generating V8 code, although the 64-bit kernel requires a V9 CPU. This patch corrects that on V9-only distros (Debian, Gentoo). Tested on `sparc64-unknown-linux-gnu`, `x86_64-pc-linux-gnu`, `sparcv9-sun-solaris2.11`, and `amd64-pc-solaris2.11`. A previous version of this patch was submitted as [[Driver][Sparc] Default to -mcpu=v9 for SparcV8 on Linux](https://reviews.llvm.org/D130688), but got stalled for 2+ years. --- Full diff: https://github.com/llvm/llvm-project/pull/109278.diff 3 Files Affected: - (modified) clang/lib/Driver/ToolChains/Arch/Sparc.cpp (+4-1) - (modified) clang/test/Preprocessor/predefined-arch-macros.c (+5-2) - (modified) clang/test/lit.cfg.py (+4) ``````````diff diff --git a/clang/lib/Driver/ToolChains/Arch/Sparc.cpp b/clang/lib/Driver/ToolChains/Arch/Sparc.cpp index f7f0a265fef68b..44eddc7603b4bd 100644 --- a/clang/lib/Driver/ToolChains/Arch/Sparc.cpp +++ b/clang/lib/Driver/ToolChains/Arch/Sparc.cpp @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #include "Sparc.h" +#include "clang/Driver/Distro.h" #include "clang/Driver/Driver.h" #include "clang/Driver/DriverDiagnostic.h" #include "clang/Driver/Options.h" @@ -125,7 +126,9 @@ std::string sparc::getSparcTargetCPU(const Driver &D, const ArgList &Args, return std::string(CPUName); } - if (Triple.getArch() == llvm::Triple::sparc && Triple.isOSSolaris()) + Distro Dist(D.getVFS(), Triple); + if (Triple.getArch() == llvm::Triple::sparc && + (Triple.isOSSolaris() || Dist.IsDebian() || Dist.IsGentoo())) return "v9"; return ""; } diff --git a/clang/test/Preprocessor/predefined-arch-macros.c b/clang/test/Preprocessor/predefined-arch-macros.c index a149c69ee0cdb2..2e576546b45c7a 100644 --- a/clang/test/Preprocessor/predefined-arch-macros.c +++ b/clang/test/Preprocessor/predefined-arch-macros.c @@ -4131,13 +4131,16 @@ // RUN: %clang -E -dM %s -o - 2>&1 \ // RUN: -target sparc-unknown-linux \ -// RUN: | FileCheck -match-full-lines %s -check-prefix=CHECK_SPARC +// RUN: | FileCheck -match-full-lines %s -check-prefixes=CHECK_SPARC,CHECK_SPARC%if sparc64-distro %{_V9%} %else %{_V8%} // CHECK_SPARC: #define __BIG_ENDIAN__ 1 // CHECK_SPARC: #define __sparc 1 // CHECK_SPARC: #define __sparc__ 1 // CHECK_SPARC-NOT: #define __sparcv9 1 // CHECK_SPARC-NOT: #define __sparcv9__ 1 -// CHECK_SPARC: #define __sparcv8 1 +// CHECK_SPARC_V8: #define __sparcv8 1 +// CHECK_SPARC_V8-NOT: #define __sparc_v9__ 1 +// CHECK_SPARC_V9: #define __sparc_v9__ 1 +// CHECK_SPARC_V9-NOT: #define __sparcv8 1 // CHECK_SPARC-NOT: #define __sparcv9 1 // CHECK_SPARC-NOT: #define __sparcv9__ 1 diff --git a/clang/test/lit.cfg.py b/clang/test/lit.cfg.py index 92a3361ce672e2..068975fac5a7a4 100644 --- a/clang/test/lit.cfg.py +++ b/clang/test/lit.cfg.py @@ -224,6 +224,10 @@ def have_host_clang_repl_cuda(): "default-cxx-stdlib={}".format(config.clang_default_cxx_stdlib) ) +# clang -m32 defaults to -mcpu=v9 on Linux/sparc64 distros. +if re.search(r"debian|gentoo", platform.version(), re.I): + config.available_features.add("sparc64-distro") + # As of 2011.08, crash-recovery tests still do not pass on FreeBSD. if platform.system() not in ["FreeBSD"]: config.available_features.add("crash-recovery") `````````` </details> https://github.com/llvm/llvm-project/pull/109278 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits