diff options
author | Ed Schonberg <schonberg@adacore.com> | 2018-05-25 09:05:21 +0000 |
---|---|---|
committer | Pierre-Marie de Rodat <pmderodat@gcc.gnu.org> | 2018-05-25 09:05:21 +0000 |
commit | 17dd35f448a689e51e8cd17138c6e942a343f894 (patch) | |
tree | 64ae599cbb238ebc57934e818b72461bf4734d29 /gcc | |
parent | bf5899e71ea7ca1cc3ae9007c2d5e06ee4108d2a (diff) | |
download | gcc-17dd35f448a689e51e8cd17138c6e942a343f894.zip gcc-17dd35f448a689e51e8cd17138c6e942a343f894.tar.gz gcc-17dd35f448a689e51e8cd17138c6e942a343f894.tar.bz2 |
[Ada] Spurious error on fixed-point operation whose operands are expressions
This patch fixes a spurious error in a fixed-point operand of a multiplying
operator M when the operand is an adding operation and the context imposes
a different fixed-point type to the result of M.
2018-05-25 Ed Schonberg <schonberg@adacore.com>
gcc/ada/
* sem_res.adb (Set_Mixed_Mode_Operand): If the operand is an expression
of a fixed point type and the parent is a multiplying operation,
resolve the operand with its own type because the context will impose a
resulting type on the result of the multiplication by means of
approriate conversion.
gcc/testsuite/
* gnat.dg/fixedpnt4.adb: New testcase.
From-SVN: r260741
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ada/ChangeLog | 8 | ||||
-rw-r--r-- | gcc/ada/sem_res.adb | 14 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/testsuite/gnat.dg/fixedpnt4.adb | 14 |
4 files changed, 38 insertions, 2 deletions
diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index ba22139..66b8491 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,11 @@ +2018-05-25 Ed Schonberg <schonberg@adacore.com> + + * sem_res.adb (Set_Mixed_Mode_Operand): If the operand is an expression + of a fixed point type and the parent is a multiplying operation, + resolve the operand with its own type because the context will impose a + resulting type on the result of the multiplication by means of + approriate conversion. + 2018-05-25 Hristian Kirtchev <kirtchev@adacore.com> * exp_ch3.adb (Default_Initialize_Object): Ensure that the analysis of diff --git a/gcc/ada/sem_res.adb b/gcc/ada/sem_res.adb index a71e583..d11296c 100644 --- a/gcc/ada/sem_res.adb +++ b/gcc/ada/sem_res.adb @@ -5283,9 +5283,19 @@ package body Sem_Res is elsif Etype (N) = T and then B_Typ /= Universal_Fixed then - -- Not a mixed-mode operation, resolve with context - Resolve (N, B_Typ); + -- if the operand is part of a fixed multiplication operation, + -- a conversion will be applied to each operand, so resolve it + -- with its own type. + + if Nkind_In (Parent (N), N_Op_Multiply, N_Op_Divide) then + Resolve (N); + + else + -- Not a mixed-mode operation, resolve with context + + Resolve (N, B_Typ); + end if; elsif Etype (N) = Any_Fixed then diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 821a12d..2b2695e 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2018-05-25 Ed Schonberg <schonberg@adacore.com> + + * gnat.dg/fixedpnt4.adb: New testcase. + 2018-05-25 Javier Miranda <miranda@adacore.com> * gnat.dg/interface7.adb: New testcase. diff --git a/gcc/testsuite/gnat.dg/fixedpnt4.adb b/gcc/testsuite/gnat.dg/fixedpnt4.adb new file mode 100644 index 0000000..5025298 --- /dev/null +++ b/gcc/testsuite/gnat.dg/fixedpnt4.adb @@ -0,0 +1,14 @@ +-- { dg-do compile } + +procedure Fixedpnt4 is + type T is delta 2.0/5.0 range -10.0 .. 10.0 with Small => 2.0/5.0; + type T2 is delta 1.0/25.0 range -10.0 .. 10.0 with Small => 1.0/25.0; + + X : T := 1.0; + Y : T2; +begin + Y := X / X; + Y := X / (X + X); + Y := X / (X + X + 1.0); + Y := (X + X) * (X + X); +end; |