aboutsummaryrefslogtreecommitdiffstats
path: root/lib/compiler/src/v3_codegen.erl
diff options
context:
space:
mode:
authorBjörn-Egil Dahlberg <[email protected]>2013-10-01 17:52:33 +0200
committerBjörn-Egil Dahlberg <[email protected]>2014-01-28 15:56:26 +0100
commite491dc2ff804107daecf36244587566210682850 (patch)
tree79dc01cdfd569981af8d95c219c607a1213682fc /lib/compiler/src/v3_codegen.erl
parent1b701e059c36154d88caa24c4aaa68a2d19971cf (diff)
downloadotp-e491dc2ff804107daecf36244587566210682850.tar.gz
otp-e491dc2ff804107daecf36244587566210682850.tar.bz2
otp-e491dc2ff804107daecf36244587566210682850.zip
compiler: Fix sorted keys in put_map instruction
All pairs in a Map needs to be in strict ascending key order.
Diffstat (limited to 'lib/compiler/src/v3_codegen.erl')
-rw-r--r--lib/compiler/src/v3_codegen.erl17
1 files changed, 12 insertions, 5 deletions
diff --git a/lib/compiler/src/v3_codegen.erl b/lib/compiler/src/v3_codegen.erl
index 667f10a7f5..e8eec08323 100644
--- a/lib/compiler/src/v3_codegen.erl
+++ b/lib/compiler/src/v3_codegen.erl
@@ -1501,11 +1501,18 @@ set_cg([{var,R}], {map,SrcMap,Es}, Le, Vdb, Bef,
{var,SrcVar} -> fetch_var(SrcVar, Int0);
_ -> SrcMap
end,
- List = flatmap(fun({map_pair,K,{var,V}}) ->
- [K,fetch_var(V, Int0)];
- ({map_pair,K,E}) ->
- [K,E]
- end, sort(Es)),
+
+ % MapPairs in put_map must be sorted in ascending Key Order
+ % Key literals must be unique when arriving here in v3_codegen
+
+ SortedEs = lists:sort(fun
+ ({map_pair,{_T1,K1},_},{map_pair,{_T2,K2},_}) when K1 < K2 -> true;
+ ({map_pair,{_,_},_},{map_pair,{_,_},_}) -> false
+ end, Es),
+ List = flatmap(fun
+ ({map_pair,K,{var,V}}) -> [K,fetch_var(V, Int0)];
+ ({map_pair,K,E}) -> [K,E]
+ end, SortedEs),
Live = max_reg(Bef#sr.reg),
Int1 = clear_dead(Int0, Le#l.i, Vdb),
Aft = Bef#sr{reg=put_reg(R, Int1#sr.reg)},