aboutsummaryrefslogtreecommitdiffstats
path: root/erts/emulator/test
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2018-12-13 10:26:20 +0100
committerBjörn Gustavsson <[email protected]>2018-12-13 10:26:20 +0100
commit3e58c9be25dbe9eb5c0cdda31f1b88d41f4d7131 (patch)
treecca722c99ea6e9a1adf68328294b3377720760c5 /erts/emulator/test
parentdcf9c02e4674ce7a0e23458be666bc03de6e0160 (diff)
parent2bf2b7009905a880f514621e8912508055df437e (diff)
downloadotp-3e58c9be25dbe9eb5c0cdda31f1b88d41f4d7131.tar.gz
otp-3e58c9be25dbe9eb5c0cdda31f1b88d41f4d7131.tar.bz2
otp-3e58c9be25dbe9eb5c0cdda31f1b88d41f4d7131.zip
Merge branch 'maint'
* maint: Fix reading beyond end of bignum in integer squaring
Diffstat (limited to 'erts/emulator/test')
-rw-r--r--erts/emulator/test/big_SUITE.erl18
1 files changed, 17 insertions, 1 deletions
diff --git a/erts/emulator/test/big_SUITE.erl b/erts/emulator/test/big_SUITE.erl
index 0a42b09903..5b602dd4dc 100644
--- a/erts/emulator/test/big_SUITE.erl
+++ b/erts/emulator/test/big_SUITE.erl
@@ -168,7 +168,11 @@ eval({op,_,Op,A0,B0}, LFH) ->
Res = eval_op(Op, A, B),
erlang:garbage_collect(),
Res;
-eval({integer,_,I}, _) -> I;
+eval({integer,_,I}, _) ->
+ %% "Parasitic" ("symbiotic"?) test of squaring all numbers
+ %% found in the test data.
+ test_squaring(I),
+ I;
eval({call,_,{atom,_,Local},Args0}, LFH) ->
Args = eval_list(Args0, LFH),
LFH(Local, Args).
@@ -192,6 +196,18 @@ eval_op('bxor', A, B) -> A bxor B;
eval_op('bsl', A, B) -> A bsl B;
eval_op('bsr', A, B) -> A bsr B.
+test_squaring(I) ->
+ %% Multiplying an integer by itself is specially optimized, so we
+ %% should take special care to test squaring. The optimization
+ %% will kick in when the two operands have the same address.
+ Sqr = I * I,
+
+ %% This expression will be multiplied in the usual way, because
+ %% the the two operands for '*' are stored at different addresses.
+ Sqr = I * ((I + id(1)) - id(1)),
+
+ ok.
+
%% Built in test functions
fac(0) -> 1;