[m-rev.] for review: fix hlc test failures with GCC 12

Julien Fischer jfischer at opturion.com
Sun Jul 3 23:54:17 AEST 2022


For review by Zoltan.

This is an alternative to the diff I posted the other day based on the
review comments for that.

----------------------------------

Fix hlc test failures with GCC 12.

GCC 12 has new warning, -Winfinite-recursion, that is being triggered by six
tests in the directory tests/valid when compiled in high-level C grades. Since
we also enable -Werror, this is causing these test to fail. Fix these failures
by either removing the infinite recursion from them or by disabling the new GCC
warning for the affected test cases.

configure.ac:
tests/DEFNS_FOR_TESTS.in:
     Define a variable whose value is the option for disabling GCC's infinite
     recursion check.

tests/valid/higher_order5.m:
tests/valid/stack_alloc.m:
     Modify these tests so they do not trigger the infinite recursion warning
     in GCC (or Mercury for that matter).

tests/valid/mode_syntax.m:
tests/valid/same_length_2.m:
     Merge these two tests (under the first name) since they both test the same
     thing.  Delete the same_length_2 version.

tests/valid/Mmakefile:
     Conform to the above deletion.

tests/valid/Mercury.options:
     Include DEFNS_FOR_TESTS here so that mmc --make can see it.

     Disable GCC's infinite recursion check for those tests that trigger
     it.

     Shut up a bunch Mercury warnings for the mode_syntax test case that
     are unrelated to what is actually being tested.

Julien.

diff --git a/configure.ac b/configure.ac
index 871cbe5..de3f295 100644
--- a/configure.ac
+++ b/configure.ac
@@ -966,6 +966,7 @@ then
      CFLAGS_FOR_NO_MOVE_LOOP_INVARIANTS=
      CFLAGS_FOR_NO_REORDER_FUNCTIONS=""
      CFLAGS_FOR_NO_TREE_DOMINATOR_OPTS=
+    CFLAGS_FOR_NO_INFINITE_RECURSION=

  else

@@ -1044,8 +1045,22 @@ EOF
      fi

      rm -f conftest*
+
+    # We need to disable the infinite recursion warning in GCC 12 and later
+    # when running some of the tests in tests/valid. The tests will fail
+    # otherwise since we also enable -Werror.
+    case "$C_COMPILER_TYPE" in
+        gcc_1[[2-9]]_*)
+            CFLAGS_FOR_NO_INFINITE_RECURSION="-Wno-infinite-recursion"
+            ;;
+        *)
+            CFLAGS_FOR_NO_INFINITE_RECURSION=
+            ;;
+    esac
+
  fi
  AC_SUBST(CFLAGS_FOR_ERRMSG_FILTER)
+AC_SUBST(CFLAGS_FOR_NO_INFINITE_RECURSION)

  #-----------------------------------------------------------------------------#
  # Make sure we search /usr/local/include and /usr/local/lib for
diff --git a/tests/DEFNS_FOR_TESTS.in b/tests/DEFNS_FOR_TESTS.in
index 2063e01..384b4b6 100644
--- a/tests/DEFNS_FOR_TESTS.in
+++ b/tests/DEFNS_FOR_TESTS.in
@@ -1 +1,2 @@
  CFLAGS_FOR_ERRMSG_FILTER=@CFLAGS_FOR_ERRMSG_FILTER@
+CFLAGS_FOR_NO_INFINITE_RECURSION=@CFLAGS_FOR_NO_INFINITE_RECURSION@
diff --git a/tests/valid/Mercury.options b/tests/valid/Mercury.options
index c8074f1..041c47a 100644
--- a/tests/valid/Mercury.options
+++ b/tests/valid/Mercury.options
@@ -2,6 +2,10 @@
  # some regression tests only failed with particular options enabled
  # (please keep these lists sorted)

+# We need to include DEFNS_FOR_TESTS here so that mmc --make can
+# see the definitions it contains.
+include ../DEFNS_FOR_TESTS
+
  # When compiling using the installed libraries, setting GRADEFLAGS may
  # may cause mgnuc to look for the `.mih' files for a non-installed grade.
  # test_mercury runs the tests using the installed libraries, so GRADEFLAGS
@@ -75,6 +79,7 @@ MCFLAGS-livevals_seq		= -O5 --opt-space
  MCFLAGS-livevars_shallow	= --no-intermodule-optimization --grade none --trace shallow
  MCFLAGS-livevars_shallow2	= --no-intermodule-optimization --grade none --trace shallow
  MCFLAGS-lco_term		= --optimize-constructor-last-call
+CFLAGS-loop_in_disj             = $(CFLAGS_FOR_NO_INFINITE_RECURSION)
  MCFLAGS-loop_inv_bug		= --common-struct --loop-invariants
  MCFLAGS-mark_static_bug		= --lookup-switch-size 1
  MCFLAGS-mc_bag			= --prop-mode-constraints
@@ -84,6 +89,8 @@ MCFLAGS-mc_hhf_nonlocals_bug	= --prop-mode-constraints
  MCFLAGS-mc_implied_modes	= --prop-mode-constraints
  MCFLAGS-middle_rec_labels	= --middle-rec
  MCFLAGS-mode_selection		= --no-warn-det-decls-too-lax
+MCFLAGS-mode_syntax             = --no-warn-det-decls-too-lax --no-warn-simple-code --no-warn-unresolved-polymorphism
+CFLAGS-mode_syntax              = $(CFLAGS_FOR_NO_INFINITE_RECURSION)
  MCFLAGS-mostly_uniq_mode_inf	= --infer-all
  MCFLAGS-mostly_uniq_neg		= --no-warn-singleton-vars
  MCFLAGS-mpj6			= --infer-all
@@ -97,6 +104,7 @@ MCFLAGS-par_dupelim		= --optimize-dups
  MCFLAGS-par_saved_const		= -O3 --optimize-saved-vars-const
  MCFLAGS-pred_with_no_modes	= --infer-all
  MCFLAGS-quantifier_warning	= --halt-at-warn
+CFLAGS-recursive_no_tag_type    = $(CFLAGS_FOR_NO_INFINITE_RECURSION)
  MCFLAGS-require_tailrec_1	= -O0 --optimise-tailcalls --warn-non-tail-recursion self
  MCFLAGS-require_tailrec_2	= -O0 --optimise-tailcalls --no-warn-non-tail-recursion
  MCFLAGS-require_tailrec_3	= -O0 --optimise-tailcalls --warn-non-tail-recursion self-and-mutual
diff --git a/tests/valid/Mmakefile b/tests/valid/Mmakefile
index 36904bb..1c3ad78 100644
--- a/tests/valid/Mmakefile
+++ b/tests/valid/Mmakefile
@@ -226,7 +226,6 @@ OTHER_PROGS = \
  	require_tailrec_2 \
  	require_tailrec_3 \
  	required_var \
-	same_length_2 \
  	semidet_disj \
  	shape_type \
  	simplify_bug \
diff --git a/tests/valid/higher_order5.m b/tests/valid/higher_order5.m
index 08d0e9e..a93938a 100644
--- a/tests/valid/higher_order5.m
+++ b/tests/valid/higher_order5.m
@@ -6,7 +6,11 @@

  :- interface.

-:- pred definite_vars(robdd(T)::in, vars_entailed_result(T)::out,
+:- type nat
+    --->    zero
+    ;       s(nat).
+
+:- pred definite_vars(nat::in, robdd(T)::in, vars_entailed_result(T)::out,
      vars_entailed_result(T)::out) is det.

  :- type robdd(T).
@@ -35,8 +39,9 @@
  :- type robdd(T)
      --->    robdd(int).

-definite_vars(R, T, F) :-
-    definite_vars(id(R), T_tr, F_tr),
+definite_vars(zero, _, all_vars, all_vars).
+definite_vars(s(N), R, T, F) :-
+    definite_vars(N, id(R), T_tr, F_tr),
      T = T_tr `intersection` T_tr,
      F = F_tr `intersection` F_tr.

diff --git a/tests/valid/mode_syntax.m b/tests/valid/mode_syntax.m
index 702c545..3067493 100644
--- a/tests/valid/mode_syntax.m
+++ b/tests/valid/mode_syntax.m
@@ -26,10 +26,13 @@
  :- implementation.

  :- pred q(list(T)::list_skel >> list_skel /* my_input_list_skel */).
+:- pred q2(list(T)::my_input_list_skel).
  :- pred r(list(T)::my_output_list_skel).

  q(_X) :-
      q([]).
+q2(_X) :-
+    q2([]).
  r(X) :-
      r(X).

diff --git a/tests/valid/same_length_2.m b/tests/valid/same_length_2.m
deleted file mode 100644
index 17c3af6..0000000
--- a/tests/valid/same_length_2.m
+++ /dev/null
@@ -1,39 +0,0 @@
-%---------------------------------------------------------------------------%
-% vim: ts=4 sw=4 et ft=mercury
-%---------------------------------------------------------------------------%
-
-:- module same_length_2.
-:- interface.
-:- import_module list.
-
-:- mode my_input_list_skel == list_skel >> list_skel.
-:- mode my_output_list_skel == free >> list_skel.
-:- mode my_list_skel_output == list_skel >> ground.
-
-:- pred p is semidet.
-
-:- pred p2(list(T)::my_output_list_skel) is nondet.
-
-:- implementation.
-
-:- pred q(list(T)::my_input_list_skel).
-:- pred r(list(T)::my_output_list_skel).
-
-q(_X) :-
-    q([]).
-
-r(X) :-
-    r(X).
-
-p :-
-    r(X),
-    q(X).
-
-p2(X) :-
-    (
-        r(X),
-        q(X)
-    ;
-        r(X),
-        q(X)
-    ).
diff --git a/tests/valid/stack_alloc.m b/tests/valid/stack_alloc.m
index 9de49d5..6f293c4 100644
--- a/tests/valid/stack_alloc.m
+++ b/tests/valid/stack_alloc.m
@@ -3,10 +3,13 @@
  %---------------------------------------------------------------------------%

  :- module stack_alloc.
-
  :- interface.

-:- pred p is semidet.
+:- type nat
+    --->    zero
+    ;       s(nat).
+
+:- pred p(nat::in) is semidet.

  :- implementation.

@@ -16,17 +19,17 @@
  :- pragma external_pred(in/1).
  :- pragma external_pred(out/1).

-p :-
+p(s(N)) :-
      (
          out(X),
          out(Y),
-        p,
+        p(N),
          in(X),
          in(Y)
      ;
          out(A),
          out(B),
-        p,
+        p(N),
          in(A),
          in(B)
      ).




More information about the reviews mailing list