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 flag '%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/Frontend/invalid-target-feature.c =================================================================== --- /dev/null +++ clang/test/Frontend/invalid-target-feature.c @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -triple aarch64-linux-gnu -target-feature '' -target-feature m %s 2>&1 \ +// RUN: | FileCheck -check-prefix=NO_PREFIX %s + +// NO_PREFIX: warning: feature flag 'm' needs to start with either '+' to enable the feature or '-' to disable it; ignoring it for now + +// RUN: %clang_cc1 -triple aarch64-linux-gnu -target-feature '' -target-feature ' n' %s 2>&1 \ +// RUN: | FileCheck -check-prefix=NULL_PREFIX %s + +// NULL_PREFIX: warning: feature flag 'n' needs to start with either '+' to enable the feature or '-' to disable it; ignoring it for now Index: clang/test/Misc/warning-flags.c =================================================================== --- clang/test/Misc/warning-flags.c +++ clang/test/Misc/warning-flags.c @@ -18,7 +18,7 @@ The list of warnings below should NEVER grow. It should gradually shrink to 0. -CHECK: Warnings without flags (66): +CHECK: Warnings without flags (67): CHECK-NEXT: ext_expected_semi_decl_list CHECK-NEXT: ext_explicit_specialization_storage_class @@ -57,6 +57,7 @@ CHECK-NEXT: warn_implements_nscopying CHECK-NEXT: warn_incompatible_qualified_id CHECK-NEXT: warn_invalid_asm_cast_lvalue +CHECK-NEXT: warn_invalid_feature_flags CHECK-NEXT: warn_maynot_respond CHECK-NEXT: warn_method_param_redefinition CHECK-NEXT: warn_missing_case_for_condition