Skip to content

Commit 0623389

Browse files
authored
[Driver] Default to -mv8plus on 32-bit Solaris/SPARC (#150176)
While investigating PR #149990, I noticed that while both the Oracle Studio compilers and GCC default to `-mv8plus` on 32-bit Solaris/SPARC, Clang does not. This patch fixes this by enabling the `v8plus` feature. Tested on `sparcv9-sun-solaris2.11` and `sparc64-unknown-linux-gnu`.
1 parent 38a977d commit 0623389

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

clang/lib/Driver/ToolChains/Arch/Sparc.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ const char *sparc::getSparcAsmModeForCPU(StringRef Name,
3737
.Case("niagara4", "-Av9d")
3838
.Default(DefV9CPU);
3939
} else {
40+
const char *DefV8CPU;
41+
42+
if (Triple.isOSSolaris())
43+
DefV8CPU = "-Av8plus";
44+
else
45+
DefV8CPU = "-Av8";
46+
4047
return llvm::StringSwitch<const char *>(Name)
4148
.Case("v8", "-Av8")
4249
.Case("supersparc", "-Av8")
@@ -72,7 +79,7 @@ const char *sparc::getSparcAsmModeForCPU(StringRef Name,
7279
.Case("gr712rc", "-Aleon")
7380
.Case("leon4", "-Aleon")
7481
.Case("gr740", "-Aleon")
75-
.Default("-Av8");
82+
.Default(DefV8CPU);
7683
}
7784
}
7885

@@ -160,6 +167,8 @@ void sparc::getSparcTargetFeatures(const Driver &D, const llvm::Triple &Triple,
160167
(Triple.getArch() == llvm::Triple::sparcv9) &&
161168
(Triple.isOSLinux() || Triple.isOSFreeBSD() || Triple.isOSOpenBSD());
162169
bool IsSparcV9BTarget = Triple.isOSSolaris();
170+
bool IsSparcV8PlusTarget =
171+
Triple.getArch() == llvm::Triple::sparc && Triple.isOSSolaris();
163172
if (Arg *A = Args.getLastArg(options::OPT_mvis, options::OPT_mno_vis)) {
164173
if (A->getOption().matches(options::OPT_mvis))
165174
Features.push_back("+vis");
@@ -196,6 +205,8 @@ void sparc::getSparcTargetFeatures(const Driver &D, const llvm::Triple &Triple,
196205
if (Arg *A = Args.getLastArg(options::OPT_mv8plus, options::OPT_mno_v8plus)) {
197206
if (A->getOption().matches(options::OPT_mv8plus))
198207
Features.push_back("+v8plus");
208+
} else if (IsSparcV8PlusTarget) {
209+
Features.push_back("+v8plus");
199210
}
200211

201212
if (Args.hasArg(options::OPT_ffixed_g1))

clang/test/Driver/sparc-target-features.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,8 @@
3939
// SOFT-QUAD-FLOAT: "-target-feature" "-hard-quad-float"
4040

4141
// RUN: %clang --target=sparc -mv8plus %s -### 2>&1 | FileCheck -check-prefix=V8PLUS %s
42+
/// 32-bit Solaris/SPARC defaults to -mv8plus
43+
// RUN: %clang --target=sparc-sun-solaris2.11 %s -### 2>&1 | FileCheck -check-prefix=V8PLUS %s
44+
// RUN: %clang --target=sparc-sun-solaris2.11 -mno-v8plus %s -### 2>&1 | FileCheck -check-prefix=NO-V8PLUS %s
4245
// V8PLUS: "-target-feature" "+v8plus"
46+
// NO-V8PLUS-NOT: "-target-feature" "+v8plus"

0 commit comments

Comments
 (0)