Skip to content

Commit 291f542

Browse files
committed
Add a test for "assume" annotation dropped without warning
1 parent ca3c14e commit 291f542

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

tests/backend/checkmach/test_assume_fail.ml

+23
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,26 @@ let[@zero_alloc strict] test68 x =
9393
carries the "assume" information of operations that were optimized away.
9494
So far, we haven't seen the need for it in a real example.
9595
*)
96+
97+
(* CR gyorsh: the check passes on g0 and fails on g1-g3 below, even though the
98+
generated code is exactly the same in all four cases. The difference is because
99+
"assume" is not propagated on partial applications. There is no misplaced
100+
attribute warning. This is the same behavior as for "@inlined" annotations.
101+
*)
102+
let[@inline never][@local never] f x y = (x,y)
103+
104+
let[@zero_alloc] g0 () =
105+
let x = (f[@zero_alloc assume]) () () in
106+
x
107+
108+
let[@zero_alloc] g1 () =
109+
let x = ((f[@zero_alloc assume]) ()) () in
110+
x
111+
112+
let[@zero_alloc] g2 () =
113+
let x = ((f ())[@zero_alloc assume]) () in
114+
x
115+
116+
let[@zero_alloc] g3 () =
117+
let x = (((f[@zero_alloc assume]) ())[@zero_alloc assume]) () in
118+
x

tests/backend/checkmach/test_assume_fail.output

+18
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,21 @@ Error: Annotation check for zero_alloc strict failed on function Test_assume_fai
4848

4949
File "test_assume_fail.ml", line 85, characters 5-9:
5050
Error: allocation of 24 bytes
51+
52+
File "test_assume_fail.ml", line 108, characters 5-15:
53+
Error: Annotation check for zero_alloc failed on function Test_assume_fail.g1 (camlTest_assume_fail.g1_HIDE_STAMP)
54+
55+
File "test_assume_fail.ml", line 109, characters 10-41:
56+
Error: called function may allocate (direct tailcall camlTest_assume_fail.f_HIDE_STAMP)
57+
58+
File "test_assume_fail.ml", line 112, characters 5-15:
59+
Error: Annotation check for zero_alloc failed on function Test_assume_fail.g2 (camlTest_assume_fail.g2_HIDE_STAMP)
60+
61+
File "test_assume_fail.ml", line 113, characters 10-41:
62+
Error: called function may allocate (direct tailcall camlTest_assume_fail.f_HIDE_STAMP)
63+
64+
File "test_assume_fail.ml", line 116, characters 5-15:
65+
Error: Annotation check for zero_alloc failed on function Test_assume_fail.g3 (camlTest_assume_fail.g3_HIDE_STAMP)
66+
67+
File "test_assume_fail.ml", line 117, characters 10-63:
68+
Error: called function may allocate (direct tailcall camlTest_assume_fail.f_HIDE_STAMP)

0 commit comments

Comments
 (0)