From debbae89f9faf47b95bd1c86058cd232783f3c3f Mon Sep 17 00:00:00 2001 From: Bernhard Schommer Date: Thu, 4 Jul 2019 12:59:33 +0200 Subject: Added new diagnostic for non-linear conditionals The new diagnostics is triggered if a conditional is used that may not be transformed into linear code by the later by the if conversion. The new diagnostic is emitted if a conditional may contain an unsafe expression or is contained within another conditional, logical and or logical or expression. An expression is unsafe if it contains a call, changes memory or if its evaluation leads to undefined behavior, for example division and modulo. Also fixes a small typo in a comment in Cutil. --- cparser/Diagnostics.ml | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'cparser/Diagnostics.ml') diff --git a/cparser/Diagnostics.ml b/cparser/Diagnostics.ml index 51dcab47..012e4b66 100644 --- a/cparser/Diagnostics.ml +++ b/cparser/Diagnostics.ml @@ -102,6 +102,7 @@ type warning_type = | Flexible_array_extensions | Tentative_incomplete_static | Reduced_alignment + | Non_linear_cond_expr (* List of active warnings *) let active_warnings: warning_type list ref = ref [ @@ -163,6 +164,7 @@ let string_of_warning = function | Flexible_array_extensions -> "flexible-array-extensions" | Tentative_incomplete_static -> "tentative-incomplete-static" | Reduced_alignment -> "reduced-alignment" + | Non_linear_cond_expr -> "non-linear-cond-expr" (* Activate the given warning *) let activate_warning w () = @@ -216,6 +218,7 @@ let wall () = Flexible_array_extensions; Tentative_incomplete_static; Reduced_alignment; + Non_linear_cond_expr; ] let wnothing () = @@ -253,6 +256,7 @@ let werror () = Flexible_array_extensions; Tentative_incomplete_static; Reduced_alignment; + Non_linear_cond_expr; ] (* Generate the warning key for the message *) @@ -437,6 +441,7 @@ let warning_options = error_option Flexible_array_extensions @ error_option Tentative_incomplete_static @ error_option Reduced_alignment @ + error_option Non_linear_cond_expr @ [Exact ("-Wfatal-errors"), Set error_fatal; Exact ("-fdiagnostics-color"), Ignore; (* Either output supports it or no color *) Exact ("-fno-diagnostics-color"), Unset color_diagnostics; @@ -492,3 +497,6 @@ let crash exn = let no_loc = ("", -1) let file_loc file = (file,-10) + +let active_warning ty = + fst (classify_warning ty) <> SuppressedMsg -- cgit