aboutsummaryrefslogtreecommitdiffstats
path: root/cparser
diff options
context:
space:
mode:
authorBernhard Schommer <bernhardschommer@gmail.com>2017-02-09 15:54:31 +0100
committerBernhard Schommer <bschommer@users.noreply.github.com>2017-02-17 14:09:56 +0100
commit4a8f7dc7e9f3f57f08cca9ca2de19214cbe4dc77 (patch)
treedf6c6de13d537ace13ef299187986d04a8c08971 /cparser
parent201ca60922ede81a0861e76f9399fc400fafb440 (diff)
downloadcompcert-kvx-4a8f7dc7e9f3f57f08cca9ca2de19214cbe4dc77.tar.gz
compcert-kvx-4a8f7dc7e9f3f57f08cca9ca2de19214cbe4dc77.zip
Extended unused vars check for params.
The test now also checks whether the parameter are used at all in the function body. Bug 19872
Diffstat (limited to 'cparser')
-rw-r--r--cparser/Cerrors.ml6
-rw-r--r--cparser/Cerrors.mli1
-rw-r--r--cparser/Checks.ml4
3 files changed, 9 insertions, 2 deletions
diff --git a/cparser/Cerrors.ml b/cparser/Cerrors.ml
index 8b2a4cd5..34fc4fcf 100644
--- a/cparser/Cerrors.ml
+++ b/cparser/Cerrors.ml
@@ -89,6 +89,7 @@ type warning_type =
| CompCert_conformance
| Inline_asm_sdump
| Unused_variable
+ | Unused_parameter
(* List of active warnings *)
let active_warnings: warning_type list ref = ref [
@@ -137,6 +138,7 @@ let string_of_warning = function
| CompCert_conformance -> "compcert-conformance"
| Inline_asm_sdump -> "inline-asm-sdump"
| Unused_variable -> "unused-variable"
+ | Unused_parameter -> "unused-parameter"
(* Activate the given warning *)
let activate_warning w () =
@@ -181,7 +183,8 @@ let wall () =
Unknown_pragmas;
CompCert_conformance;
Inline_asm_sdump;
- Unused_variable
+ Unused_variable;
+ Unused_parameter
]
let wnothing () =
@@ -373,6 +376,7 @@ let warning_options =
error_option CompCert_conformance @
error_option Inline_asm_sdump @
error_option Unused_variable @
+ error_option Unused_parameter @
[Exact ("-Wfatal-errors"), Set error_fatal;
Exact ("-fdiagnostics-color"), Ignore; (* Either output supports it or no color *)
Exact ("-fno-diagnostics-color"), Unset color_diagnostics;
diff --git a/cparser/Cerrors.mli b/cparser/Cerrors.mli
index fb987bca..c351443c 100644
--- a/cparser/Cerrors.mli
+++ b/cparser/Cerrors.mli
@@ -46,6 +46,7 @@ type warning_type =
| CompCert_conformance (** features that are not part of the CompCert C core language *)
| Inline_asm_sdump (** inline assembler used in combination of sdump *)
| Unused_variable (** unused local variables *)
+ | Unused_parameter (** unused function parameter *)
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
diff --git a/cparser/Checks.ml b/cparser/Checks.ml
index 5ce51aba..dc08e254 100644
--- a/cparser/Checks.ml
+++ b/cparser/Checks.ml
@@ -167,5 +167,7 @@ let unused_variables p =
| Gfundef fd ->
let dec_env,used_env = vars_used_stmt (IdentMap.empty,IdentSet.empty) fd.fd_body in
IdentMap.iter (fun id loc -> if not (IdentSet.mem id used_env) then
- warning loc Unused_variable "unused variable '%s'" id.name) dec_env
+ warning loc Unused_variable "unused variable '%s'" id.name) dec_env;
+ List.iter (fun (id,_) -> if not (IdentSet.mem id used_env) then
+ warning g.gloc Unused_parameter "unused parameter '%s'" id.name) fd.fd_params
| _ -> ()) p