* don't perform the "/ const" to "* (1/const)" transformation for comp-typed

expressions, since comp cannot represent fractions (bug reported at
    http://lists.freepascal.org/pipermail/fpc-pascal/2016-June/048234.html )

git-svn-id: trunk@34035 -
This commit is contained in:
Jonas Maebe 2016-06-30 15:33:51 +00:00
parent 996e325175
commit ec5dea1092
3 changed files with 34 additions and 2 deletions

1
.gitattributes vendored
View File

@ -10971,6 +10971,7 @@ tests/tbs/tb0617.pp svneol=native#text/pascal
tests/tbs/tb0618.pp svneol=native#text/plain
tests/tbs/tb0619.pp svneol=native#text/pascal
tests/tbs/tb0620.pp svneol=native#text/pascal
tests/tbs/tb0621.pp svneol=native#text/plain
tests/tbs/tb205.pp svneol=native#text/plain
tests/tbs/tb610.pp svneol=native#text/pascal
tests/tbs/tb613.pp svneol=native#text/plain

View File

@ -697,8 +697,12 @@ implementation
an slash expresion would be first converted into a multiplication and later
folded }
if (nodetype=slashn) and
{ do not mess with currency types }
(not(is_currency(right.resultdef))) and
{ do not mess with currency and comp types }
(not(is_currency(right.resultdef)) and
not((right.resultdef.typ=floatdef) and
(tfloatdef(right.resultdef).floattype=s64comp)
)
) and
(((cs_opt_fastmath in current_settings.optimizerswitches) and (rt=ordconstn)) or
((cs_opt_fastmath in current_settings.optimizerswitches) and (rt=realconstn) and
(bestrealrec(trealconstnode(right).value_real).SpecialType in [fsPositive,fsNegative])

27
tests/tbs/tb0621.pp Normal file
View File

@ -0,0 +1,27 @@
PROGRAM compbug300;
VAR x1, x2 : comp;
(* Dividing 8 / 2 doesn't work with fpc 3.0.0
but works for example with fpc 2.6.4
Markus Greim / 29.jun.2016 *)
BEGIN
x1 := 8;
writeln('x1 : ',x1);
x2 := x1 / 2;
writeln('x2 = x1/2 should be 4 but is : ', x2);
if x2<>4 then
halt(1);
x2 := x1 / 4;
writeln('x2 = x1/4 should be 2 but is : ', x2);
if x2<>2 then
halt(2);
x2 := x1 / 8.0;
writeln('x2 = x1/8.0 should be 1 and is : ', x2);
if x2<>1 then
halt(3);
END.