diff --git a/clang/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp --- a/clang/lib/Basic/Targets/PPC.cpp +++ b/clang/lib/Basic/Targets/PPC.cpp @@ -228,33 +228,25 @@ static bool ppcUserFeaturesCheck(DiagnosticsEngine &Diags, const std::vector &FeaturesVec) { - if (llvm::find(FeaturesVec, "-vsx") != FeaturesVec.end()) { - if (llvm::find(FeaturesVec, "+power8-vector") != FeaturesVec.end()) { - Diags.Report(diag::err_opt_not_valid_with_opt) << "-mpower8-vector" - << "-mno-vsx"; - return false; - } - - if (llvm::find(FeaturesVec, "+direct-move") != FeaturesVec.end()) { - Diags.Report(diag::err_opt_not_valid_with_opt) << "-mdirect-move" - << "-mno-vsx"; - return false; - } - - if (llvm::find(FeaturesVec, "+float128") != FeaturesVec.end()) { - Diags.Report(diag::err_opt_not_valid_with_opt) << "-mfloat128" - << "-mno-vsx"; - return false; + // vsx was not explicitly turned off. + if (llvm::find(FeaturesVec, "-vsx") == FeaturesVec.end()) + return true; + + auto FindVSXSubfeature = [&](StringRef Feature, StringRef Option) { + if (llvm::find(FeaturesVec, Feature) != FeaturesVec.end()) { + Diags.Report(diag::err_opt_not_valid_with_opt) << Option << "-mno-vsx"; + return true; } + return false; + }; - if (llvm::find(FeaturesVec, "+power9-vector") != FeaturesVec.end()) { - Diags.Report(diag::err_opt_not_valid_with_opt) << "-mpower9-vector" - << "-mno-vsx"; - return false; - } - } + bool Found = FindVSXSubfeature("+power8-vector", "-mpower8-vector"); + Found |= FindVSXSubfeature("+direct-move", "-mdirect-move"); + Found |= FindVSXSubfeature("+float128", "-mfloat128"); + Found |= FindVSXSubfeature("+power9-vector", "-mpower9-vector"); - return true; + // Return false if any vsx subfeatures was found. + return !Found; } bool PPCTargetInfo::initFeatureMap( diff --git a/clang/test/Driver/ppc-dependent-options.cpp b/clang/test/Driver/ppc-dependent-options.cpp --- a/clang/test/Driver/ppc-dependent-options.cpp +++ b/clang/test/Driver/ppc-dependent-options.cpp @@ -54,6 +54,10 @@ // RUN: -mcpu=power9 -std=c++11 -mno-vsx -mfloat128 %s 2>&1 | \ // RUN: FileCheck %s -check-prefix=CHECK-NVSX-FLT128 +// RUN: not %clang -target powerpc64le-unknown-unknown -fsyntax-only \ +// RUN: -mcpu=power9 -std=c++11 -mno-vsx -mfloat128 -mpower9-vector %s 2>&1 | \ +// RUN: FileCheck %s -check-prefix=CHECK-NVSX-MULTI + #ifdef __VSX__ static_assert(false, "VSX enabled"); #endif @@ -78,5 +82,7 @@ // CHECK-NVSX-P9V: error: option '-mpower9-vector' cannot be specified with '-mno-vsx' // CHECK-NVSX-FLT128: error: option '-mfloat128' cannot be specified with '-mno-vsx' // CHECK-NVSX-DMV: error: option '-mdirect-move' cannot be specified with '-mno-vsx' +// CHECK-NVSX-MULTI: error: option '-mfloat128' cannot be specified with '-mno-vsx' +// CHECK-NVSX-MULTI: error: option '-mpower9-vector' cannot be specified with '-mno-vsx' // CHECK-NVSX: Neither enabled // CHECK-VSX: VSX enabled