Index: clang/include/clang/Basic/DiagnosticCommonKinds.td =================================================================== --- clang/include/clang/Basic/DiagnosticCommonKinds.td +++ clang/include/clang/Basic/DiagnosticCommonKinds.td @@ -327,6 +327,8 @@ "option '%0' cannot be specified on this target">; def err_invalid_feature_combination : Error< "invalid feature combination: %0">; +def warn_invalid_feature_flags : Warning< + "feature flags '%0' should start with '+' or '-'">; // Source manager def err_cannot_open_file : Error<"cannot open file '%0': %1">, DefaultFatal; Index: clang/lib/Basic/TargetInfo.cpp =================================================================== --- clang/lib/Basic/TargetInfo.cpp +++ clang/lib/Basic/TargetInfo.cpp @@ -493,10 +493,14 @@ llvm::StringMap &Features, DiagnosticsEngine &Diags, StringRef CPU, const std::vector &FeatureVec) const { for (const auto &F : FeatureVec) { + if (F.empty()) + continue; StringRef Name = F; // Apply the feature via the target. - bool Enabled = Name[0] == '+'; - setFeatureEnabled(Features, Name.substr(1), Enabled); + if (Name[0] != '+' && Name[0] != '-') + Diags.Report(diag::warn_invalid_feature_flags) << Name; + else + setFeatureEnabled(Features, Name.substr(1), Name[0] == '+'); } return true; } Index: clang/test/Driver/invalid-target-feature.c =================================================================== --- /dev/null +++ clang/test/Driver/invalid-target-feature.c @@ -0,0 +1,5 @@ +// RUN: %clang -c -target aarch64 -Xclang -target-feature -Xclang '' -Xclang -target-feature -Xclang m %s 2>&1 \ +// RUN: | FileCheck --check-prefix=XCLANG %s + +// XCLANG: warning: feature flags 'm' should start with '+' or '-' +//