From 4809f9bcd2f9b1473fa0d8b1db56cc6887ff814c Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Mon, 10 Feb 2014 19:06:37 +0000 Subject: [PATCH] Basic: Clean up malformed pragma diagnostics Create a new diagnostic, -Wignored-pragmas and use it to handle any case where a pragma would have a side effect but is ignored. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@201102 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticGroups.td | 2 + include/clang/Basic/DiagnosticLexKinds.td | 5 ++- include/clang/Basic/DiagnosticParseKinds.td | 42 ++++++++++++--------- include/clang/Basic/DiagnosticSemaKinds.td | 18 ++++++--- lib/Parse/ParseOpenMP.cpp | 2 +- lib/Parse/ParsePragma.cpp | 2 +- test/Misc/warning-flags.c | 24 +----------- 7 files changed, 45 insertions(+), 50 deletions(-) diff --git a/include/clang/Basic/DiagnosticGroups.td b/include/clang/Basic/DiagnosticGroups.td index 441b5af4cd..01aad56102 100644 --- a/include/clang/Basic/DiagnosticGroups.td +++ b/include/clang/Basic/DiagnosticGroups.td @@ -339,6 +339,8 @@ def UninitializedStaticSelfInit : DiagGroup<"static-self-init">; def Uninitialized : DiagGroup<"uninitialized", [UninitializedSometimes, UninitializedStaticSelfInit]>; def UnknownPragmas : DiagGroup<"unknown-pragmas">; +def IgnoredPragmas : DiagGroup<"ignored-pragmas">; +def Pragmas : DiagGroup<"pragmas", [UnknownPragmas, IgnoredPragmas]>; def UnknownWarningOption : DiagGroup<"unknown-warning-option">; def NSobjectAttribute : DiagGroup<"NSObject-attribute">; def UnknownAttributes : DiagGroup<"unknown-attributes">; diff --git a/include/clang/Basic/DiagnosticLexKinds.td b/include/clang/Basic/DiagnosticLexKinds.td index 0edf376c52..4607eb0532 100644 --- a/include/clang/Basic/DiagnosticLexKinds.td +++ b/include/clang/Basic/DiagnosticLexKinds.td @@ -437,7 +437,8 @@ def err_pragma_message_malformed : Error< def err_pragma_push_pop_macro_malformed : Error< "pragma %0 requires a parenthesized string">; def warn_pragma_pop_macro_no_push : Warning< - "pragma pop_macro could not pop '%0', no matching push_macro">; + "pragma pop_macro could not pop '%0', no matching push_macro">, + InGroup; def warn_pragma_message : Warning<"%0">, InGroup, DefaultWarnNoWerror; def err_pragma_message : Error<"%0">; @@ -472,7 +473,7 @@ def warn_pragma_diagnostic_unknown_warning : InGroup; // - #pragma __debug def warn_pragma_debug_unexpected_command : Warning< - "unexpected debug command '%0'">; + "unexpected debug command '%0'">, InGroup; def err_defined_macro_name : Error<"'defined' cannot be used as a macro name">; def err_paste_at_start : Error< diff --git a/include/clang/Basic/DiagnosticParseKinds.td b/include/clang/Basic/DiagnosticParseKinds.td index ff76e959c3..b269313fce 100644 --- a/include/clang/Basic/DiagnosticParseKinds.td +++ b/include/clang/Basic/DiagnosticParseKinds.td @@ -763,32 +763,40 @@ def err_type_trait_arity : Error< // Language specific pragmas // - Generic warnings def warn_pragma_expected_lparen : Warning< - "missing '(' after '#pragma %0' - ignoring">; + "missing '(' after '#pragma %0' - ignoring">, InGroup; def warn_pragma_expected_rparen : Warning< - "missing ')' after '#pragma %0' - ignoring">; + "missing ')' after '#pragma %0' - ignoring">, InGroup; def warn_pragma_expected_identifier : Warning< - "expected identifier in '#pragma %0' - ignored">; + "expected identifier in '#pragma %0' - ignored">, InGroup; def warn_pragma_ms_struct : Warning< - "incorrect use of '#pragma ms_struct on|off' - ignored">; + "incorrect use of '#pragma ms_struct on|off' - ignored">, + InGroup; def warn_pragma_extra_tokens_at_eol : Warning< - "extra tokens at end of '#pragma %0' - ignored">; + "extra tokens at end of '#pragma %0' - ignored">, + InGroup; +def warn_pragma_expected_punc : Warning< + "expected ')' or ',' in '#pragma %0'">, InGroup; // - #pragma options def warn_pragma_options_expected_align : Warning< - "expected 'align' following '#pragma options' - ignored">; + "expected 'align' following '#pragma options' - ignored">, + InGroup; def warn_pragma_align_expected_equal : Warning< - "expected '=' following '#pragma %select{align|options align}0' - ignored">; + "expected '=' following '#pragma %select{align|options align}0' - ignored">, + InGroup; def warn_pragma_align_invalid_option : Warning< - "invalid alignment option in '#pragma %select{align|options align}0' - ignored">; + "invalid alignment option in '#pragma %select{align|options align}0' - ignored">, + InGroup; // - #pragma pack def warn_pragma_pack_invalid_action : Warning< - "unknown action for '#pragma pack' - ignored">; + "unknown action for '#pragma pack' - ignored">, + InGroup; def warn_pragma_pack_malformed : Warning< - "expected integer or identifier in '#pragma pack' - ignored">; + "expected integer or identifier in '#pragma pack' - ignored">, + InGroup; // - #pragma unused def warn_pragma_unused_expected_var : Warning< - "expected '#pragma unused' argument to be a variable name">; -def warn_pragma_unused_expected_punc : Warning< - "expected ')' or ',' in '#pragma unused'">; + "expected '#pragma unused' argument to be a variable name">, + InGroup; // - #pragma fp_contract def err_pragma_fp_contract_scope : Error< "'#pragma fp_contract' can only appear at file scope or at the start of a " @@ -808,11 +816,11 @@ def err_not_opencl_storage_class_specifier : Error< // OpenCL EXTENSION pragma (OpenCL 1.1 [9.1]) def warn_pragma_expected_colon : Warning< - "missing ':' after %0 - ignoring">; + "missing ':' after %0 - ignoring">, InGroup; def warn_pragma_expected_enable_disable : Warning< - "expected 'enable' or 'disable' - ignoring">; + "expected 'enable' or 'disable' - ignoring">, InGroup; def warn_pragma_unknown_extension : Warning< - "unknown OpenCL extension %0 - ignoring">; + "unknown OpenCL extension %0 - ignoring">, InGroup; def err_seh_expected_handler : Error< "expected '__except' or '__finally' block">; @@ -837,7 +845,7 @@ def err_omp_unknown_directive : Error < def err_omp_unexpected_directive : Error < "unexpected OpenMP directive '#pragma omp %0'">; def err_omp_expected_punc : Error < - "expected ',' or ')' in %select{'#pragma omp %1'|'%1' clause}0">; + "expected ',' or ')' in '%0' clause">; def err_omp_unexpected_clause : Error < "unexpected OpenMP clause '%0' in directive '#pragma omp %1'">; def err_omp_more_one_clause : Error < diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index edbf97e500..93d5948ce8 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -469,22 +469,28 @@ def err_opencl_half_return : Error< "declaring function return value of type %0 is not allowed; did you forget * ?">; def warn_enum_value_overflow : Warning<"overflow in enumeration value">; def warn_pragma_options_align_reset_failed : Warning< - "#pragma options align=reset failed: %0">; + "#pragma options align=reset failed: %0">, + InGroup; def err_pragma_options_align_mac68k_target_unsupported : Error< "mac68k alignment pragma is not supported on this target">; def warn_pragma_pack_invalid_alignment : Warning< - "expected #pragma pack parameter to be '1', '2', '4', '8', or '16'">; + "expected #pragma pack parameter to be '1', '2', '4', '8', or '16'">, + InGroup; // Follow the MSVC implementation. def warn_pragma_pack_show : Warning<"value of #pragma pack(show) == %0">; def warn_pragma_pack_pop_identifer_and_alignment : Warning< "specifying both a name and alignment to 'pop' is undefined">; -def warn_pragma_pack_pop_failed : Warning<"#pragma pack(pop, ...) failed: %0">; -def warn_pragma_ms_struct_failed : Warning<"#pramga ms_struct can not be used with dynamic classes or structures">, InGroup; +def warn_pragma_pack_pop_failed : Warning<"#pragma pack(pop, ...) failed: %0">, + InGroup; +def warn_pragma_ms_struct_failed : Warning<"#pramga ms_struct can not be used with dynamic classes or structures">, + InGroup; def warn_pragma_unused_undeclared_var : Warning< - "undeclared variable %0 used as an argument for '#pragma unused'">; + "undeclared variable %0 used as an argument for '#pragma unused'">, + InGroup; def warn_pragma_unused_expected_var_arg : Warning< - "only variables can be arguments to '#pragma unused'">; + "only variables can be arguments to '#pragma unused'">, + InGroup; def err_pragma_push_visibility_mismatch : Error< "#pragma visibility push with no matching #pragma visibility pop">; def note_surrounding_namespace_ends_here : Note< diff --git a/lib/Parse/ParseOpenMP.cpp b/lib/Parse/ParseOpenMP.cpp index d10207d833..9053407a5f 100644 --- a/lib/Parse/ParseOpenMP.cpp +++ b/lib/Parse/ParseOpenMP.cpp @@ -367,7 +367,7 @@ OMPClause *Parser::ParseOpenMPVarListClause(OpenMPClauseKind Kind) { } else if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::annot_pragma_openmp_end)) { Diag(Tok, diag::err_omp_expected_punc) - << 1 << getOpenMPClauseName(Kind); + << getOpenMPClauseName(Kind); } } diff --git a/lib/Parse/ParsePragma.cpp b/lib/Parse/ParsePragma.cpp index a225c766c1..41562a44e9 100644 --- a/lib/Parse/ParsePragma.cpp +++ b/lib/Parse/ParsePragma.cpp @@ -530,7 +530,7 @@ void PragmaUnusedHandler::HandlePragma(Preprocessor &PP, } // Illegal token! - PP.Diag(Tok.getLocation(), diag::warn_pragma_unused_expected_punc); + PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_punc) << "unused"; return; } diff --git a/test/Misc/warning-flags.c b/test/Misc/warning-flags.c index cd7f0a2237..4f3519530c 100644 --- a/test/Misc/warning-flags.c +++ b/test/Misc/warning-flags.c @@ -18,7 +18,7 @@ This test serves two purposes: The list of warnings below should NEVER grow. It should gradually shrink to 0. -CHECK: Warnings without flags (133): +CHECK: Warnings without flags (111): CHECK-NEXT: ext_delete_void_ptr_operand CHECK-NEXT: ext_expected_semi_decl_list CHECK-NEXT: ext_explicit_specialization_storage_class @@ -108,30 +108,8 @@ CHECK-NEXT: warn_pp_convert_lhs_to_positive CHECK-NEXT: warn_pp_convert_rhs_to_positive CHECK-NEXT: warn_pp_expr_overflow CHECK-NEXT: warn_pp_line_decimal -CHECK-NEXT: warn_pragma_align_expected_equal -CHECK-NEXT: warn_pragma_align_invalid_option -CHECK-NEXT: warn_pragma_debug_unexpected_command -CHECK-NEXT: warn_pragma_expected_colon -CHECK-NEXT: warn_pragma_expected_enable_disable -CHECK-NEXT: warn_pragma_expected_identifier -CHECK-NEXT: warn_pragma_expected_lparen -CHECK-NEXT: warn_pragma_expected_rparen -CHECK-NEXT: warn_pragma_extra_tokens_at_eol -CHECK-NEXT: warn_pragma_ms_struct -CHECK-NEXT: warn_pragma_options_align_reset_failed -CHECK-NEXT: warn_pragma_options_expected_align -CHECK-NEXT: warn_pragma_pack_invalid_action -CHECK-NEXT: warn_pragma_pack_invalid_alignment -CHECK-NEXT: warn_pragma_pack_malformed -CHECK-NEXT: warn_pragma_pack_pop_failed CHECK-NEXT: warn_pragma_pack_pop_identifer_and_alignment CHECK-NEXT: warn_pragma_pack_show -CHECK-NEXT: warn_pragma_pop_macro_no_push -CHECK-NEXT: warn_pragma_unknown_extension -CHECK-NEXT: warn_pragma_unused_expected_punc -CHECK-NEXT: warn_pragma_unused_expected_var -CHECK-NEXT: warn_pragma_unused_expected_var_arg -CHECK-NEXT: warn_pragma_unused_undeclared_var CHECK-NEXT: warn_property_attr_mismatch CHECK-NEXT: warn_property_attribute CHECK-NEXT: warn_property_getter_owning_mismatch -- 2.40.0