aboutsummaryrefslogtreecommitdiffstats
path: root/lib/hipe/test/basic_SUITE_data
diff options
context:
space:
mode:
authorKostis Sagonas <[email protected]>2015-11-30 00:42:56 +0100
committerKostis Sagonas <[email protected]>2015-12-16 22:08:34 +0100
commitc3e5a1ea98d2dae23aa6d050f93b7912dbe6f43c (patch)
tree26e415b92fd2f2ed2c9a04ce5a67cd55a2918702 /lib/hipe/test/basic_SUITE_data
parente91d465773e349409476ab8c85f9967a4fb7cc4a (diff)
downloadotp-c3e5a1ea98d2dae23aa6d050f93b7912dbe6f43c.tar.gz
otp-c3e5a1ea98d2dae23aa6d050f93b7912dbe6f43c.tar.bz2
otp-c3e5a1ea98d2dae23aa6d050f93b7912dbe6f43c.zip
Test that apply/3 is tail recursive
Diffstat (limited to 'lib/hipe/test/basic_SUITE_data')
-rw-r--r--lib/hipe/test/basic_SUITE_data/basic_tail_rec.erl39
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/hipe/test/basic_SUITE_data/basic_tail_rec.erl b/lib/hipe/test/basic_SUITE_data/basic_tail_rec.erl
new file mode 100644
index 0000000000..0124f13df6
--- /dev/null
+++ b/lib/hipe/test/basic_SUITE_data/basic_tail_rec.erl
@@ -0,0 +1,39 @@
+%%% -*- erlang-indent-level: 2 -*-
+%%%-------------------------------------------------------------------
+%%% Author: Kostis Sagonas
+%%%
+%%% Contains tests that check that tail recursion optimization occurs.
+%%%-------------------------------------------------------------------
+-module(basic_tail_rec).
+
+-export([test/0]).
+-export([app0/2]). %% used in an apply/3 call
+
+test() ->
+ ok = test_app_tail(),
+ ok.
+
+%%--------------------------------------------------------------------
+%% Written by Mikael Pettersson: check that apply is tail recursive.
+
+%% Increased the following quantity from 20 to 30 so that the test
+%% remains valid even with the naive register allocator. - Kostis
+-define(SIZE_INCREASE, 30).
+
+test_app_tail() ->
+ Inc = start(400),
+ %% io:format("Inc ~w\n", [Inc]),
+ case Inc > ?SIZE_INCREASE of
+ true ->
+ {error, "apply/3 is not tail recursive in native code"};
+ false ->
+ ok
+ end.
+
+start(N) ->
+ app0(N, hipe_bifs:nstack_used_size()).
+
+app0(0, Size0) ->
+ hipe_bifs:nstack_used_size() - Size0;
+app0(N, Size) ->
+ apply(?MODULE, app0, [N-1, Size]).