From 4e5fb2c6a8345eaf9bcd42ce25788caa8365fec1 Mon Sep 17 00:00:00 2001 From: florian Date: Sun, 22 Jul 2018 13:11:21 +0000 Subject: [PATCH] * might_have_sideeffects gets flags: if mhs_exceptions is passed, nodes which might cause an exception are considered as having a side effect git-svn-id: branches/laksen/riscv_new@39483 - (cherry picked from commit 32a58ba7d10605f9ccd0563f69ce7511d1e812f0) --- compiler/nadd.pas | 2 +- compiler/nutils.pas | 20 +++++++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/compiler/nadd.pas b/compiler/nadd.pas index 32fe2349fa..bb992fde89 100644 --- a/compiler/nadd.pas +++ b/compiler/nadd.pas @@ -1011,7 +1011,7 @@ implementation end; end { short to full boolean evalution possible and useful? } - else if not(might_have_sideeffects(right)) and not(cs_full_boolean_eval in localswitches) then + else if not(might_have_sideeffects(right,[mhs_exceptions])) and not(cs_full_boolean_eval in localswitches) then begin case nodetype of andn,orn: diff --git a/compiler/nutils.pas b/compiler/nutils.pas index 4276ccc61a..3bcfa01e0c 100644 --- a/compiler/nutils.pas +++ b/compiler/nutils.pas @@ -54,6 +54,14 @@ interface then the parent node is processed again } pm_postandagain); + + tmhs_flag = ( + { exceptions (overflow, sigfault etc.) are considered as side effect } + mhs_exceptions + ); + tmhs_flags = set of tmhs_flag; + pmhs_flags = ^tmhs_flags; + foreachnodefunction = function(var n: tnode; arg: pointer): foreachnoderesult of object; staticforeachnodefunction = function(var n: tnode; arg: pointer): foreachnoderesult; @@ -117,7 +125,7 @@ interface function genloadfield(n: tnode; const fieldname: string): tnode; { returns true, if the tree given might have side effects } - function might_have_sideeffects(n : tnode) : boolean; + function might_have_sideeffects(n : tnode;const flags : tmhs_flags = []) : boolean; { returns true, if n contains nodes which might be conditionally executed } function has_conditional_nodes(n : tnode) : boolean; @@ -1371,13 +1379,19 @@ implementation in_finalize_x,in_new_x,in_dispose_x,in_exit,in_copy_x,in_initialize_x,in_leave,in_cycle, in_and_assign_x_y,in_or_assign_x_y,in_xor_assign_x_y,in_sar_assign_x_y,in_shl_assign_x_y, in_shr_assign_x_y,in_rol_assign_x_y,in_ror_assign_x_y,in_neg_assign_x,in_not_assign_x]) + ) or + ((mhs_exceptions in pmhs_flags(arg)^) and + ((n.nodetype in [derefn,vecn]) or + ((n.nodetype in [addn,subn,muln,divn,slashn,unaryminusn]) and (n.localswitches*[cs_check_overflow,cs_check_range]<>[])) + ) ) then result:=fen_norecurse_true; end; - function might_have_sideeffects(n : tnode) : boolean; + + function might_have_sideeffects(n : tnode; const flags : tmhs_flags) : boolean; begin - result:=foreachnodestatic(n,@check_for_sideeffect,nil); + result:=foreachnodestatic(n,@check_for_sideeffect,@flags); end;