diff --git a/ocaml/parsing/builtin_attributes.ml b/ocaml/parsing/builtin_attributes.ml index 96c693fa1fa..c17cd7e5558 100644 --- a/ocaml/parsing/builtin_attributes.ml +++ b/ocaml/parsing/builtin_attributes.ml @@ -585,11 +585,14 @@ let zero_alloc_attribute (attr : Parsetree.attribute) = parse_attribute_with_ident_payload attr ~name:"zero_alloc" ~f:(function | "check" -> Clflags.zero_alloc_check := Clflags.Annotations.Check_default + | "check_opt" -> Clflags.zero_alloc_check := Clflags.Annotations.Check_opt_only + | "check_all" -> Clflags.zero_alloc_check := Clflags.Annotations.Check_all + | "check_none" -> Clflags.zero_alloc_check := Clflags.Annotations.No_check | "all" -> Clflags.zero_alloc_check_assert_all := true | _ -> warn_payload attr.attr_loc attr.attr_name.txt - "Only 'check' and 'all' are supported") + "Only 'all', 'check', 'check_opt', 'check_all', and 'check_none' are supported") let afl_inst_ratio_attribute attr = clflags_attribute_with_int_payload attr diff --git a/tests/backend/checkmach/dune.inc b/tests/backend/checkmach/dune.inc index ffe9024b59a..49fb5ccf114 100644 --- a/tests/backend/checkmach/dune.inc +++ b/tests/backend/checkmach/dune.inc @@ -654,3 +654,79 @@ (enabled_if (= %{context_name} "main")) (deps test_misplaced_attr.output test_misplaced_attr.output.corrected) (action (diff test_misplaced_attr.output test_misplaced_attr.output.corrected))) + +(rule + (enabled_if (= %{context_name} "main")) + (targets test_attr_check.output.corrected) + (deps (:ml test_attr_check.ml) filter.sh) + (action + (with-outputs-to test_attr_check.output.corrected + (pipe-outputs + (with-accepted-exit-codes 2 + (run %{bin:ocamlopt.opt} %{ml} -g -color never -error-style short -c + -zero-alloc-check all -checkmach-details-cutoff 20 -O3)) + (run "./filter.sh") + )))) + +(rule + (alias runtest) + (enabled_if (= %{context_name} "main")) + (deps test_attr_check.output test_attr_check.output.corrected) + (action (diff test_attr_check.output test_attr_check.output.corrected))) + +(rule + (enabled_if (= %{context_name} "main")) + (targets test_attr_check_all.output.corrected) + (deps (:ml test_attr_check_all.ml) filter.sh) + (action + (with-outputs-to test_attr_check_all.output.corrected + (pipe-outputs + (with-accepted-exit-codes 2 + (run %{bin:ocamlopt.opt} %{ml} -g -color never -error-style short -c + -zero-alloc-check default -checkmach-details-cutoff 20 -O3)) + (run "./filter.sh") + )))) + +(rule + (alias runtest) + (enabled_if (= %{context_name} "main")) + (deps test_attr_check_all.output test_attr_check_all.output.corrected) + (action (diff test_attr_check_all.output test_attr_check_all.output.corrected))) + +(rule + (enabled_if (= %{context_name} "main")) + (targets test_attr_check_opt.output.corrected) + (deps (:ml test_attr_check_opt.ml) filter.sh) + (action + (with-outputs-to test_attr_check_opt.output.corrected + (pipe-outputs + (with-accepted-exit-codes 2 + (run %{bin:ocamlopt.opt} %{ml} -g -color never -error-style short -c + -zero-alloc-check default -checkmach-details-cutoff 20 -O3)) + (run "./filter.sh") + )))) + +(rule + (alias runtest) + (enabled_if (= %{context_name} "main")) + (deps test_attr_check_opt.output test_attr_check_opt.output.corrected) + (action (diff test_attr_check_opt.output test_attr_check_opt.output.corrected))) + +(rule + (enabled_if (= %{context_name} "main")) + (targets test_attr_check_none.output.corrected) + (deps (:ml test_attr_check_none.ml) filter.sh) + (action + (with-outputs-to test_attr_check_none.output.corrected + (pipe-outputs + (with-accepted-exit-codes 0 + (run %{bin:ocamlopt.opt} %{ml} -g -color never -error-style short -c + -zero-alloc-check default -checkmach-details-cutoff 20 -O3)) + (run "./filter.sh") + )))) + +(rule + (alias runtest) + (enabled_if (= %{context_name} "main")) + (deps test_attr_check_none.output test_attr_check_none.output.corrected) + (action (diff test_attr_check_none.output test_attr_check_none.output.corrected))) diff --git a/tests/backend/checkmach/gen/gen_dune.ml b/tests/backend/checkmach/gen/gen_dune.ml index 6ac5e950d19..fd84036e418 100644 --- a/tests/backend/checkmach/gen/gen_dune.ml +++ b/tests/backend/checkmach/gen/gen_dune.ml @@ -128,5 +128,8 @@ let () = print_test_expected_output ~cutoff:default_cutoff ~flambda_only:false ~extra_dep:None ~exit_code:2 "test_assume_on_call"; print_test_expected_output ~cutoff:default_cutoff ~flambda_only:false ~extra_dep:None ~exit_code:2 "test_misplaced_assume"; print_test_expected_output ~cutoff:default_cutoff ~flambda_only:false ~extra_dep:None ~exit_code:0 "test_misplaced_attr"; - + print_test_expected_output ~extra_flags:"-zero-alloc-check all" ~cutoff:default_cutoff ~flambda_only:false ~extra_dep:None ~exit_code:2 "test_attr_check"; + print_test_expected_output ~cutoff:default_cutoff ~flambda_only:false ~extra_dep:None ~exit_code:2 "test_attr_check_all"; + print_test_expected_output ~cutoff:default_cutoff ~flambda_only:false ~extra_dep:None ~exit_code:2 "test_attr_check_opt"; + print_test_expected_output ~cutoff:default_cutoff ~flambda_only:false ~extra_dep:None ~exit_code:0 "test_attr_check_none"; () diff --git a/tests/backend/checkmach/test_attr_check.ml b/tests/backend/checkmach/test_attr_check.ml new file mode 100644 index 00000000000..3e62e20f172 --- /dev/null +++ b/tests/backend/checkmach/test_attr_check.ml @@ -0,0 +1,3 @@ +[@@@zero_alloc check] +let[@zero_alloc] test x = (x,x) +let[@zero_alloc opt] test_opt x = (x,x) diff --git a/tests/backend/checkmach/test_attr_check.output b/tests/backend/checkmach/test_attr_check.output new file mode 100644 index 00000000000..6ba61f7d7e3 --- /dev/null +++ b/tests/backend/checkmach/test_attr_check.output @@ -0,0 +1,5 @@ +File "test_attr_check.ml", line 2, characters 5-15: +Error: Annotation check for zero_alloc failed on function Test_attr_check.test (camlTest_attr_check.test_HIDE_STAMP) + +File "test_attr_check.ml", line 2, characters 26-31: +Error: Unexpected allocation of 24 bytes diff --git a/tests/backend/checkmach/test_attr_check_all.ml b/tests/backend/checkmach/test_attr_check_all.ml new file mode 100644 index 00000000000..f816de68b46 --- /dev/null +++ b/tests/backend/checkmach/test_attr_check_all.ml @@ -0,0 +1,3 @@ +[@@@zero_alloc check_all] +let[@zero_alloc] test x = (x,x) +let[@zero_alloc opt] test_opt x = (x,x) diff --git a/tests/backend/checkmach/test_attr_check_all.output b/tests/backend/checkmach/test_attr_check_all.output new file mode 100644 index 00000000000..715f1deaf4b --- /dev/null +++ b/tests/backend/checkmach/test_attr_check_all.output @@ -0,0 +1,11 @@ +File "test_attr_check_all.ml", line 2, characters 5-15: +Error: Annotation check for zero_alloc failed on function Test_attr_check_all.test (camlTest_attr_check_all.test_HIDE_STAMP) + +File "test_attr_check_all.ml", line 2, characters 26-31: +Error: Unexpected allocation of 24 bytes + +File "test_attr_check_all.ml", line 3, characters 5-15: +Error: Annotation check for zero_alloc failed on function Test_attr_check_all.test_opt (camlTest_attr_check_all.test_opt_HIDE_STAMP) + +File "test_attr_check_all.ml", line 3, characters 34-39: +Error: Unexpected allocation of 24 bytes diff --git a/tests/backend/checkmach/test_attr_check_none.ml b/tests/backend/checkmach/test_attr_check_none.ml new file mode 100644 index 00000000000..299e06f049a --- /dev/null +++ b/tests/backend/checkmach/test_attr_check_none.ml @@ -0,0 +1,3 @@ +[@@@zero_alloc check_none] +let[@zero_alloc] test x = (x,x) +let[@zero_alloc opt] test_opt x = (x,x) diff --git a/tests/backend/checkmach/test_attr_check_none.output b/tests/backend/checkmach/test_attr_check_none.output new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/backend/checkmach/test_attr_check_opt.ml b/tests/backend/checkmach/test_attr_check_opt.ml new file mode 100644 index 00000000000..78e4a54e6a9 --- /dev/null +++ b/tests/backend/checkmach/test_attr_check_opt.ml @@ -0,0 +1,3 @@ +[@@@zero_alloc check_opt] +let[@zero_alloc] test x = (x,x) +let[@zero_alloc opt] test_opt x = (x,x) diff --git a/tests/backend/checkmach/test_attr_check_opt.output b/tests/backend/checkmach/test_attr_check_opt.output new file mode 100644 index 00000000000..8acfa0195a8 --- /dev/null +++ b/tests/backend/checkmach/test_attr_check_opt.output @@ -0,0 +1,5 @@ +File "test_attr_check_opt.ml", line 3, characters 5-15: +Error: Annotation check for zero_alloc failed on function Test_attr_check_opt.test_opt (camlTest_attr_check_opt.test_opt_HIDE_STAMP) + +File "test_attr_check_opt.ml", line 3, characters 34-39: +Error: Unexpected allocation of 24 bytes diff --git a/tests/backend/checkmach/test_misplaced_attr.ml b/tests/backend/checkmach/test_misplaced_attr.ml index 9ea59d44d82..9e1b0011b63 100644 --- a/tests/backend/checkmach/test_misplaced_attr.ml +++ b/tests/backend/checkmach/test_misplaced_attr.ml @@ -5,3 +5,5 @@ let[@zero_alloc assume] foo = let[@zero_alloc] bar = let x = 42 in fun z -> z + x + +[@@@zero_alloc default] diff --git a/tests/backend/checkmach/test_misplaced_attr.output b/tests/backend/checkmach/test_misplaced_attr.output index a85ab2f18a5..a8c3cbe3c41 100644 --- a/tests/backend/checkmach/test_misplaced_attr.output +++ b/tests/backend/checkmach/test_misplaced_attr.output @@ -1,3 +1,7 @@ +File "test_misplaced_attr.ml", line 9, characters 0-23: +Warning 47 [attribute-payload]: illegal payload for attribute 'zero_alloc'. +Only 'all', 'check', 'check_opt', 'check_all', and 'check_none' are supported + File "test_misplaced_attr.ml", line 1, characters 5-15: Warning 53 [misplaced-attribute]: the "zero_alloc" attribute cannot appear in this context