From 201ca60922ede81a0861e76f9399fc400fafb440 Mon Sep 17 00:00:00 2001 From: Bernhard Schommer Date: Thu, 9 Feb 2017 11:07:06 +0100 Subject: Added a simple check for unused variables. The check test whether the identifier is used at all in the function and if not issue a warning. It is not tested whether the usage is reachable at all, so int i; if (0) i; would not generate a warning. This is the same as gcc/clang does. The warning is disabled per default, but is active if -Wall is given. Bug 19872 --- cparser/Cerrors.ml | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'cparser/Cerrors.ml') diff --git a/cparser/Cerrors.ml b/cparser/Cerrors.ml index dffd9c14..8b2a4cd5 100644 --- a/cparser/Cerrors.ml +++ b/cparser/Cerrors.ml @@ -88,6 +88,7 @@ type warning_type = | Unknown_pragmas | CompCert_conformance | Inline_asm_sdump + | Unused_variable (* List of active warnings *) let active_warnings: warning_type list ref = ref [ @@ -135,6 +136,7 @@ let string_of_warning = function | Unknown_pragmas -> "unknown-pragmas" | CompCert_conformance -> "compcert-conformance" | Inline_asm_sdump -> "inline-asm-sdump" + | Unused_variable -> "unused-variable" (* Activate the given warning *) let activate_warning w () = @@ -179,6 +181,7 @@ let wall () = Unknown_pragmas; CompCert_conformance; Inline_asm_sdump; + Unused_variable ] let wnothing () = @@ -207,6 +210,7 @@ let werror () = Unknown_pragmas; CompCert_conformance; Inline_asm_sdump; + Unused_variable; ] (* Generate the warning key for the message *) @@ -368,6 +372,7 @@ let warning_options = error_option Unknown_pragmas @ error_option CompCert_conformance @ error_option Inline_asm_sdump @ + error_option Unused_variable @ [Exact ("-Wfatal-errors"), Set error_fatal; Exact ("-fdiagnostics-color"), Ignore; (* Either output supports it or no color *) Exact ("-fno-diagnostics-color"), Unset color_diagnostics; -- cgit