aboutsummaryrefslogtreecommitdiffstats
path: root/lib/compiler/src/sys_core_fold.erl
diff options
context:
space:
mode:
authorAnthony Ramine <[email protected]>2014-03-08 02:31:53 +0100
committerAnthony Ramine <[email protected]>2014-03-10 02:37:10 +0100
commit4777f33ece33aaaa5066730b950f185cbd5ae816 (patch)
treedb57597f62d5c6eda64f12f6274900655e2ac194 /lib/compiler/src/sys_core_fold.erl
parent870737ab657433c5e8751255fe3c4d298202d142 (diff)
downloadotp-4777f33ece33aaaa5066730b950f185cbd5ae816.tar.gz
otp-4777f33ece33aaaa5066730b950f185cbd5ae816.tar.bz2
otp-4777f33ece33aaaa5066730b950f185cbd5ae816.zip
Properly handle redundant boolean clauses in sys_core_fold
Boolean case expressions with redundant clauses could make the compiler crash: case X == 0 of false -> no; false -> no; true -> yes end. Reported-by: Ulf Norell
Diffstat (limited to 'lib/compiler/src/sys_core_fold.erl')
-rw-r--r--lib/compiler/src/sys_core_fold.erl11
1 files changed, 8 insertions, 3 deletions
diff --git a/lib/compiler/src/sys_core_fold.erl b/lib/compiler/src/sys_core_fold.erl
index 6fdeea51d1..058abd3357 100644
--- a/lib/compiler/src/sys_core_fold.erl
+++ b/lib/compiler/src/sys_core_fold.erl
@@ -1810,9 +1810,14 @@ opt_bool_clauses([#c_clause{pats=[#c_literal{val=Lit}],
true ->
%% This clause will match.
C = C0#c_clause{body=opt_bool_case(B)},
- case Lit of
- false -> [C|opt_bool_clauses(Cs, SeenT, true)];
- true -> [C|opt_bool_clauses(Cs, true, SeenF)]
+ case {Lit,SeenT,SeenF} of
+ {false,_,false} ->
+ [C|opt_bool_clauses(Cs, SeenT, true)];
+ {true,false,_} ->
+ [C|opt_bool_clauses(Cs, true, SeenF)];
+ _ ->
+ add_warning(C, nomatch_shadow),
+ opt_bool_clauses(Cs, SeenT, SeenF)
end
end;
opt_bool_clauses([#c_clause{pats=Ps,guard=#c_literal{val=true}}=C|Cs], SeenT, SeenF) ->