Skip to content

Revised handling of unknown warnings #554

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions cparser/Diagnostics.ml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ let reset () = num_errors := 0; num_warnings := 0

exception Abort

(* Locations are (filename, line number) pairs *)

let no_loc = ("", -1)

let file_loc file = (file,-10)

(* [fatal_error_raw] is identical to [fatal_error], except it uses [Printf]
to print its message, as opposed to [Format], and does not automatically
introduce indentation and a final dot into the message. This is useful
Expand Down Expand Up @@ -106,6 +112,7 @@ type warning_type =
| Non_linear_cond_expr
| Invalid_UTF8
| Dollar_in_identifier
| Unknown_warning

(* List of all warnings with default status.
"true" means the warning is active by default.
Expand Down Expand Up @@ -143,7 +150,8 @@ let all_warnings =
(Reduced_alignment, false);
(Non_linear_cond_expr, false);
(Invalid_UTF8, true);
(Dollar_in_identifier, false)
(Dollar_in_identifier, false);
(Unknown_warning, true)
]

(* List of active warnings *)
Expand Down Expand Up @@ -188,6 +196,7 @@ let string_of_warning = function
| Non_linear_cond_expr -> "non-linear-cond-expr"
| Invalid_UTF8 -> "invalid-utf8"
| Dollar_in_identifier -> "dollar-in-identifier-extension"
| Unknown_warning -> "unknown-warning-option"

(* Activate the given warning *)
let activate_warning w () =
Expand Down Expand Up @@ -363,13 +372,15 @@ let check_errors () =
raise Abort
end

let unknown_warning w =
warning no_loc Unknown_warning "Unknown warning option %s, ignored." w

let error_option w =
let key = string_of_warning w in
[Exact ("-W"^key), Unit (activate_warning w);
Exact ("-Wno-"^key), Unit (deactivate_warning w);
Exact ("-Werror="^key), Unit (warning_as_error w);
Exact ("-Wno-error="^key), Unit ( warning_not_as_error w)]
Exact ("-Wno-error="^key), Unit (warning_not_as_error w)]

let warning_options =
List.concat (List.map (fun (w, active) -> error_option w) all_warnings) @
Expand All @@ -379,6 +390,8 @@ let warning_options =
Exact ("-Werror"), Unit werror;
Exact ("-Wall"), Unit wall;
Exact ("-w"), Unit wnothing;
_Regexp("-Wno-.*$"), Ignore;
_Regexp("-W.*$"), Self unknown_warning;
longopt_int ("-fmax-errors") ((:=) max_error);
Exact("-fno-diagnostics-show-option"),Unset diagnostics_show_option;
Exact("-fdiagnostics-show-option"),Set diagnostics_show_option;
Expand Down Expand Up @@ -425,9 +438,5 @@ let crash exn =
exit 2
end

let no_loc = ("", -1)

let file_loc file = (file,-10)

let active_warning ty =
fst (classify_warning ty) <> SuppressedMsg
1 change: 1 addition & 0 deletions cparser/Diagnostics.mli
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ type warning_type =
| Non_linear_cond_expr (** condition that cannot be linearized *)
| Invalid_UTF8 (** invalid UTF-8 encoding *)
| Dollar_in_identifier (** '$' sign in identifier *)
| Unknown_warning (** unknown warning in '-W' option *)

val warning : (string * int) -> warning_type -> ('a, Format.formatter, unit, unit, unit, unit) format6 -> 'a
(** [warning (f,c) w fmt arg1 ... argN] formats the arguments [arg1] to [argN] as warining according to
Expand Down