diff mbox

[Ada] Crash on expression function with fixed point types

Message ID 20170425082959.GA75862@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet April 25, 2017, 8:29 a.m. UTC
The compiler may crash processing a conditional expression that is
part of an arithmetic expression computing a fixed point value. After
this patch the following test compiles without errors.

procedure P (B : Boolean) is
   type Fixed is delta 0.01 range -100.0 .. 100.0;
   X : Fixed := 10.0;
begin
   X := X * (case B is when True => 1.0, when False => -1.0);
end;

Command: gcc -c p.adb

Tested on x86_64-pc-linux-gnu, committed on trunk

2017-04-25  Javier Miranda  <miranda@adacore.com>

	* sem_res.adb (Set_Mixed_Mode_Operand): A universal
	real conditional expression can appear in a fixed-type context
	and must be resolved with that context to facilitate the code
	generation to the backend.
diff mbox

Patch

Index: sem_res.adb
===================================================================
--- sem_res.adb	(revision 247135)
+++ sem_res.adb	(working copy)
@@ -5353,6 +5353,16 @@ 
                Resolve (Op2, T2);
             end;
 
+         --  A universal real conditional expression can appear in a fixed-type
+         --  context and must be resolved with that context to facilitate the
+         --  code generation to the backend.
+
+         elsif Nkind_In (N, N_Case_Expression, N_If_Expression)
+           and then Etype (N) = Universal_Real
+           and then Is_Fixed_Point_Type (B_Typ)
+         then
+            Resolve (N, B_Typ);
+
          else
             Resolve (N);
          end if;