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' needs to start with either '+' to enable the feature or '-' to disable it; ignoring it for now">; // 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 @@ -494,9 +494,14 @@ const std::vector &FeatureVec) const { for (const auto &F : FeatureVec) { StringRef Name = F; + Name = Name.trim(); + if (Name.empty()) + continue; // 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,9 @@ +// RUN: %clang -c -target aarch64 -Xclang -target-feature -Xclang '' -Xclang -target-feature -Xclang m %s 2>&1 \ +// RUN: | FileCheck -check-prefix=NO_PREFIX %s + +// NO_PREFIX: warning: feature flags 'm' needs to start with either '+' to enable the feature or '-' to disable it; ignoring it for now + +// RUN: %clang -c -target aarch64 -Xclang -target-feature -Xclang ' ' -Xclang -target-feature -Xclang ' n' %s 2>&1 \ +// RUN: | FileCheck -check-prefix=NULL_PREFIX %s + +// NULL_PREFIX: warning: feature flags 'n' needs to start with either '+' to enable the feature or '-' to disable it; ignoring it for now