Skip to content

Commit 4792f91

Browse files
Chen Zhengnemanjai
Chen Zheng
andauthored
[PowerPC] Diagnose invalid combination with Altivec, VSX and soft-float (#79109)
Moved from https://reviews.llvm.org/D126302 The current behaviour with these three options is quite undesirable: -mno-altivec -mvsx allows VSX to override no Altivec, thereby turning on both -msoft-float -maltivec causes a crash if an actual Altivec instruction is required because soft float turns of Altivec -msoft-float -mvsx is also accepted with both Altivec and VSX turned off (potentially causing crashes as above) This patch diagnoses these impossible combinations in the driver so the user does not end up with surprises in terms of their options being ignored or silently overridden. Fixes #55556 --------- Co-authored-by: Nemanja Ivanovic <[email protected]>
1 parent 0a3b5ec commit 4792f91

File tree

3 files changed

+52
-9
lines changed

3 files changed

+52
-9
lines changed

clang/lib/Basic/Targets/PPC.cpp

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -442,19 +442,44 @@ void PPCTargetInfo::getTargetDefines(const LangOptions &Opts,
442442
// _CALL_DARWIN
443443
}
444444

445-
// Handle explicit options being passed to the compiler here: if we've
446-
// explicitly turned off vsx and turned on any of:
447-
// - power8-vector
448-
// - direct-move
449-
// - float128
450-
// - power9-vector
451-
// - paired-vector-memops
452-
// - mma
453-
// - power10-vector
445+
// Handle explicit options being passed to the compiler here:
446+
// - if we've explicitly turned off vsx and turned on any of:
447+
// - power8-vector
448+
// - direct-move
449+
// - float128
450+
// - power9-vector
451+
// - paired-vector-memops
452+
// - mma
453+
// - power10-vector
454+
// - if we've explicitly turned on vsx and turned off altivec.
455+
// - if we've explicitly turned off hard-float and turned on altivec.
454456
// then go ahead and error since the customer has expressed an incompatible
455457
// set of options.
456458
static bool ppcUserFeaturesCheck(DiagnosticsEngine &Diags,
457459
const std::vector<std::string> &FeaturesVec) {
460+
// Cannot allow soft-float with Altivec.
461+
if (llvm::is_contained(FeaturesVec, "-hard-float") &&
462+
llvm::is_contained(FeaturesVec, "+altivec")) {
463+
Diags.Report(diag::err_opt_not_valid_with_opt) << "-msoft-float"
464+
<< "-maltivec";
465+
return false;
466+
}
467+
468+
// Cannot allow soft-float with VSX.
469+
if (llvm::is_contained(FeaturesVec, "-hard-float") &&
470+
llvm::is_contained(FeaturesVec, "+vsx")) {
471+
Diags.Report(diag::err_opt_not_valid_with_opt) << "-msoft-float"
472+
<< "-mvsx";
473+
return false;
474+
}
475+
476+
// Cannot allow VSX with no Altivec.
477+
if (llvm::is_contained(FeaturesVec, "+vsx") &&
478+
llvm::is_contained(FeaturesVec, "-altivec")) {
479+
Diags.Report(diag::err_opt_not_valid_with_opt) << "-mvsx"
480+
<< "-mno-altivec";
481+
return false;
482+
}
458483

459484
// vsx was not explicitly turned off.
460485
if (!llvm::is_contained(FeaturesVec, "-vsx"))
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
// RUN: not %clang_cc1 -triple powerpc64le-linux-gnu -emit-llvm %s -o -
22

33
long __attribute__((target("power8-vector,no-vsx"))) foo (void) { return 0; } // expected-error {{option '-mpower8-vector' cannot be specified with '-mno-vsx'}}
4+
long __attribute__((target("no-altivec,vsx"))) foo2(void) { return 0; } // expected-error {{option '-mvsx' cannot be specified with '-mno-altivec'}}
5+
long __attribute__((target("no-hard-float,altivec"))) foo3(void) { return 0; } // expected-error {{option '-msoft-float' cannot be specified with '-maltivec'}}
6+
long __attribute__((target("no-hard-float,vsx"))) foo4(void) { return 0; } // expected-error {{option '-msoft-float' cannot be specified with '-mvsx'}}
47

clang/test/Driver/ppc-dependent-options.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,18 @@
7878
// RUN: -mcpu=power10 -std=c++11 -mno-vsx -mpower10-vector %s 2>&1 | \
7979
// RUN: FileCheck %s -check-prefix=CHECK-NVSX-P10V
8080

81+
// RUN: not %clang -target powerpc64le-unknown-unknown -fsyntax-only \
82+
// RUN: -std=c++11 -mvsx -mno-altivec %s 2>&1 | \
83+
// RUN: FileCheck %s -check-prefix=CHECK-NALTI-VSX
84+
85+
// RUN: not %clang -target powerpc64le-unknown-unknown -fsyntax-only \
86+
// RUN: -std=c++11 -msoft-float -maltivec %s 2>&1 | \
87+
// RUN: FileCheck %s -check-prefix=CHECK-SOFTFLT-ALTI
88+
89+
// RUN: not %clang -target powerpc64le-unknown-unknown -fsyntax-only \
90+
// RUN: -std=c++11 -msoft-float -mvsx %s 2>&1 | \
91+
// RUN: FileCheck %s -check-prefix=CHECK-SOFTFLT-VSX
92+
8193
#ifdef __VSX__
8294
static_assert(false, "VSX enabled");
8395
#endif
@@ -114,3 +126,6 @@ static_assert(false, "Neither enabled");
114126
// CHECK-NVSX-MMA: error: option '-mmma' cannot be specified with '-mno-vsx'
115127
// CHECK-NVSX: Neither enabled
116128
// CHECK-VSX: VSX enabled
129+
// CHECK-NALTI-VSX: error: option '-mvsx' cannot be specified with '-mno-altivec'
130+
// CHECK-SOFTFLT-ALTI: error: option '-msoft-float' cannot be specified with '-maltivec'
131+
// CHECK-SOFTFLT-VSX: error: option '-msoft-float' cannot be specified with '-mvsx'

0 commit comments

Comments
 (0)