diff --git a/compiler/nadd.pas b/compiler/nadd.pas index 7b34b44102..4107edb4fc 100644 --- a/compiler/nadd.pas +++ b/compiler/nadd.pas @@ -1142,7 +1142,9 @@ implementation end; end { optimize a/a and a-a } - else if (cs_opt_level2 in current_settings.optimizerswitches) and (nodetype in [slashn,subn]) and + else if (((cs_opt_level2 in current_settings.optimizerswitches) and (nodetype=subn)) or + (([cs_opt_fastmath,cs_opt_level2]*current_settings.optimizerswitches=[cs_opt_fastmath,cs_opt_level2]) and (nodetype=slashn)) + ) and left.isequal(right) and not(might_have_sideeffects(left,[mhs_exceptions])) then begin case nodetype of diff --git a/tests/tbs/tb0704.pp b/tests/tbs/tb0704.pp new file mode 100644 index 0000000000..f37ce2af67 --- /dev/null +++ b/tests/tbs/tb0704.pp @@ -0,0 +1,14 @@ +{ %opt=-Oonofastmath -CE -Oonoconstprop } +{$mode objfpc} +uses + sysutils; +var + a : real; +begin + try + writeln(a/a); + except + halt(0); + end; + halt(1); +end. diff --git a/tests/tbs/tb0705.pp b/tests/tbs/tb0705.pp new file mode 100644 index 0000000000..a71fb0f78d --- /dev/null +++ b/tests/tbs/tb0705.pp @@ -0,0 +1,14 @@ +{ %opt=-O4 -CE -Oonoconstprop } +{$mode objfpc} +uses + sysutils; +var + a : real; +begin + try + writeln(a/a); + except + halt(1); + end; + halt(0); +end.