diff options
author | Anthony Ramine <[email protected]> | 2014-03-01 17:26:56 +0100 |
---|---|---|
committer | Anthony Ramine <[email protected]> | 2014-03-05 10:18:15 +0100 |
commit | 926be4d0a3a75f48bc280a7aa2f97fc4adbef189 (patch) | |
tree | ce0074eeaffcfd38187cb9609471deb4242a0b44 /lib/compiler/src | |
parent | c199bd2923e7d733e60beb9bd27b3852cbb2e699 (diff) | |
download | otp-926be4d0a3a75f48bc280a7aa2f97fc4adbef189.tar.gz otp-926be4d0a3a75f48bc280a7aa2f97fc4adbef189.tar.bz2 otp-926be4d0a3a75f48bc280a7aa2f97fc4adbef189.zip |
Do not try to optimize non-boolean guards
Expressions such as erlang:'or'(bar, true) can make beam_bool crash if it tries
to optimize them, as this code is not quite really written by users, no attempt
to rewrite them more efficiently should be done, for simplicity's sake.
Reported-by: Ulf Norell
Diffstat (limited to 'lib/compiler/src')
-rw-r--r-- | lib/compiler/src/beam_bool.erl | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/lib/compiler/src/beam_bool.erl b/lib/compiler/src/beam_bool.erl index 590665514b..0fdd0a5451 100644 --- a/lib/compiler/src/beam_bool.erl +++ b/lib/compiler/src/beam_bool.erl @@ -527,7 +527,9 @@ bopt_cg({prot,Pre0,Tree}, Fail, Rs0, Acc, St0) -> bopt_cg({atom,true}, _Fail, _Rs, Acc, St) -> {Acc,St}; bopt_cg({atom,false}, Fail, _Rs, Acc, St) -> - {[{jump,{f,Fail}}|Acc],St}. + {[{jump,{f,Fail}}|Acc],St}; +bopt_cg(_, _, _, _, _) -> + throw(not_boolean_expr). bopt_cg_not({'and',As0}) -> As = [bopt_cg_not(A) || A <- As0], @@ -540,7 +542,9 @@ bopt_cg_not({'not',Arg}) -> bopt_cg_not({test,Test,Fail,As}) -> {inverted_test,Test,Fail,As}; bopt_cg_not({atom,Bool}) when is_boolean(Bool) -> - {atom,not Bool}. + {atom,not Bool}; +bopt_cg_not(_) -> + throw(not_boolean_expr). bopt_cg_not_not({'and',As}) -> {'and',[bopt_cg_not_not(A) || A <- As]}; |