[Ada] Adding support for unsupported type conversion in CCG
diff mbox series

Message ID 20191213095501.GA13995@adacore.com
State New
Headers show
Series
  • [Ada] Adding support for unsupported type conversion in CCG
Related show

Commit Message

Pierre-Marie de Rodat Dec. 13, 2019, 9:55 a.m. UTC
Generate an extra temporary for the unchecked conversion of a function
call returning a composite type, and for the unchecked conversion to a
composite type of a function call returning a discrete type (since the C
backend does not support such cases).

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

2019-12-13  Javier Miranda  <miranda@adacore.com>

gcc/ada/

	* exp_ch4.adb (Expand_N_Unchecked_Type_Conversion): Generate an
	extra temporary for cases unsupported by the C backend.

Patch
diff mbox series

--- gcc/ada/exp_ch4.adb
+++ gcc/ada/exp_ch4.adb
@@ -12471,6 +12471,27 @@  package body Exp_Ch4 is
          end;
       end if;
 
+      --  Generate an extra temporary for cases unsupported by the C backend
+
+      if Modify_Tree_For_C then
+         declare
+            Source     : constant Node_Id := Unqual_Conv (Expression (N));
+            Source_Typ : Entity_Id        := Get_Full_View (Etype (Source));
+
+         begin
+            if Is_Packed_Array (Source_Typ) then
+               Source_Typ := Packed_Array_Impl_Type (Source_Typ);
+            end if;
+
+            if Nkind (Source) = N_Function_Call
+              and then (Is_Composite_Type (Etype (Source))
+                          or else Is_Composite_Type (Target_Type))
+            then
+               Force_Evaluation (Source);
+            end if;
+         end;
+      end if;
+
       --  Nothing to do if conversion is safe
 
       if Safe_Unchecked_Type_Conversion (N) then