Skip to content

Commit 0b6b2f9

Browse files
authored
flambda-backend: Zero alloc misplaced attr warning (#2153)
* Fix missing warning for misplaced attribute * Add a test
1 parent b74ea89 commit 0b6b2f9

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

lambda/translattribute.ml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ let is_opaque_attribute =
5454
[ ["opaque"; "ocaml.opaque"], true ]
5555

5656

57-
let find_attribute p attributes =
57+
let find_attribute ?mark_used p attributes =
5858
let inline_attribute =
59-
Builtin_attributes.filter_attributes
59+
Builtin_attributes.filter_attributes ?mark:mark_used
6060
(Builtin_attributes.Attributes_filter.create p)
6161
attributes
6262
in
@@ -461,9 +461,9 @@ let add_local_attribute expr loc attributes =
461461
end
462462
| _ -> expr
463463

464-
let assume_zero_alloc attributes =
464+
let assume_zero_alloc ?mark_used attributes =
465465
let p = Zero_alloc in
466-
let attr = find_attribute (is_property_attribute p) attributes in
466+
let attr = find_attribute ?mark_used (is_property_attribute p) attributes in
467467
match parse_property_attribute attr p with
468468
| Default_check -> false
469469
| Ignore_assert_all _ -> false
@@ -478,7 +478,7 @@ let get_assume_zero_alloc ~with_warnings attributes =
478478
that affect [Scoped_location] settings before translation
479479
of expressions in that scope.
480480
Warnings will be produced by [add_check_attribute]. *)
481-
Warnings.without_warnings (fun () -> assume_zero_alloc attributes)
481+
Warnings.without_warnings (fun () -> assume_zero_alloc ~mark_used:false attributes)
482482

483483
let add_check_attribute expr loc attributes =
484484
let to_string = function

parsing/builtin_attributes.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,11 +435,11 @@ module Attributes_filter = struct
435435
let create (t : t) = t
436436
end
437437

438-
let filter_attributes (nms_and_conds : Attributes_filter.t) attrs =
438+
let filter_attributes ?(mark=true) (nms_and_conds : Attributes_filter.t) attrs =
439439
List.filter (fun a ->
440440
List.exists (fun (nms, cond) ->
441441
if List.mem a.attr_name.txt nms
442-
then (mark_used a.attr_name; cond)
442+
then (if mark then mark_used a.attr_name; cond)
443443
else false)
444444
nms_and_conds
445445
) attrs

parsing/builtin_attributes.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ end
159159
count as misplaced if the compiler could use it in some configuration.
160160
*)
161161
val filter_attributes :
162+
?mark:bool ->
162163
Attributes_filter.t -> Parsetree.attributes -> Parsetree.attributes
163164

164165
val warn_on_literal_pattern: Parsetree.attributes -> bool

0 commit comments

Comments
 (0)