aboutsummaryrefslogtreecommitdiffstats
path: root/lib/compiler/src/beam_bool.erl
diff options
context:
space:
mode:
authorErlang/OTP <[email protected]>2009-12-14 12:54:41 +0000
committerErlang/OTP <[email protected]>2009-12-14 12:54:41 +0000
commit47b882a585b5a226bd00b5125bac948ba9268c7f (patch)
tree16b9b5e3e572e13c16db227af0397a644541d9f1 /lib/compiler/src/beam_bool.erl
parent76623933ce8b95f3be52c06311374370e94f1348 (diff)
parent88efa63b733b627934fb7eec6236c71d7acfe082 (diff)
downloadotp-47b882a585b5a226bd00b5125bac948ba9268c7f.tar.gz
otp-47b882a585b5a226bd00b5125bac948ba9268c7f.tar.bz2
otp-47b882a585b5a226bd00b5125bac948ba9268c7f.zip
Merge branch 'bg/compiler-bopt-bug' into ccase/r13b04_dev
* bg/compiler-bopt-bug: beam_bool: Fix generation of code that does not validate Fix crash in beam_bool OTP-8338 Using complex boolean expressions in ifs could cause the compiler to either crash or teminate with an internal error. (Thanks to Simon Cornish.)
Diffstat (limited to 'lib/compiler/src/beam_bool.erl')
-rw-r--r--lib/compiler/src/beam_bool.erl27
1 files changed, 17 insertions, 10 deletions
diff --git a/lib/compiler/src/beam_bool.erl b/lib/compiler/src/beam_bool.erl
index d8c201a194..dcc6ad4c7c 100644
--- a/lib/compiler/src/beam_bool.erl
+++ b/lib/compiler/src/beam_bool.erl
@@ -123,6 +123,12 @@ bopt_block(Reg, Fail, OldIs, [{block,Bl0}|Acc0], St0) ->
throw:mixed ->
failed;
+ %% There was a reference to a boolean expression
+ %% from inside a protected block (try/catch), to
+ %% a boolean expression outside.
+ throw:protected_barrier ->
+ failed;
+
%% The 'xor' operator was used. We currently don't
%% find it worthwile to translate 'xor' operators
%% (the code would be clumsy).
@@ -167,7 +173,7 @@ bopt_block(Reg, Fail, OldIs, [{block,Bl0}|Acc0], St0) ->
%% whether the optimized code is guaranteed to work in the same
%% way as the original code.
%%
-%% Throws an exception if the optmization is not safe.
+%% Throw an exception if the optimization is not safe.
%%
ensure_opt_safe(Bl, NewCode, OldIs, Fail, PreceedingCode, St) ->
%% Here are the conditions that must be true for the
@@ -184,10 +190,10 @@ ensure_opt_safe(Bl, NewCode, OldIs, Fail, PreceedingCode, St) ->
%% by the code that follows.
%%
%% 3. Any register that is assigned a value in the optimized
- %% code must be UNUSED or KILLED in the following code.
- %% (Possible future improvement: Registers that are known
- %% to be assigned the SAME value in the original and optimized
- %% code don't need to be unused in the following code.)
+ %% code must be UNUSED or KILLED in the following code
+ %% (because the register might be assigned the wrong value,
+ %% and even if the value is right it might no longer be
+ %% assigned on *all* paths leading to its use).
InitInPreceeding = initialized_regs(PreceedingCode),
@@ -304,6 +310,8 @@ dst_regs([{set,[D],_,{bif,_,{f,_}}}|Is], Acc) ->
dst_regs(Is, [D|Acc]);
dst_regs([{set,[D],_,{alloc,_,{gc_bif,_,{f,_}}}}|Is], Acc) ->
dst_regs(Is, [D|Acc]);
+dst_regs([{set,[D],_,move}|Is], Acc) ->
+ dst_regs(Is, [D|Acc]);
dst_regs([_|Is], Acc) ->
dst_regs(Is, Acc);
dst_regs([], Acc) -> ordsets:from_list(Acc).
@@ -414,11 +422,10 @@ bopt_good_args([A|As], Regs) ->
bopt_good_args([], _) -> ok.
bopt_good_arg({Tag,_}=X, Regs) when Tag =:= x; Tag =:= tmp ->
- case gb_trees:get(X, Regs) of
- any -> ok;
- _Other ->
- %%io:format("not any: ~p: ~p\n", [X,_Other]),
- throw(mixed)
+ case gb_trees:lookup(X, Regs) of
+ {value,any} -> ok;
+ {value,_} -> throw(mixed);
+ none -> throw(protected_barrier)
end;
bopt_good_arg(_, _) -> ok.