From ec5dea10925760b0b69725f02cf29545c47cacff Mon Sep 17 00:00:00 2001 From: Jonas Maebe Date: Thu, 30 Jun 2016 15:33:51 +0000 Subject: [PATCH] * 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 - --- .gitattributes | 1 + compiler/nadd.pas | 8 ++++++-- tests/tbs/tb0621.pp | 27 +++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 tests/tbs/tb0621.pp diff --git a/.gitattributes b/.gitattributes index 0ca8294185..abb7a4b630 100644 --- a/.gitattributes +++ b/.gitattributes @@ -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 diff --git a/compiler/nadd.pas b/compiler/nadd.pas index f895ec4139..3a05e7165a 100644 --- a/compiler/nadd.pas +++ b/compiler/nadd.pas @@ -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]) diff --git a/tests/tbs/tb0621.pp b/tests/tbs/tb0621.pp new file mode 100644 index 0000000000..476d6af001 --- /dev/null +++ b/tests/tbs/tb0621.pp @@ -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.