diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog
index 9c104ec..0123986 100644
--- a/gcc/ada/ChangeLog
+++ b/gcc/ada/ChangeLog
@@ -1,3 +1,11 @@
+2018-01-11  Javier Miranda  <miranda@adacore.com>
+
+	* exp_util.adb (Remove_Side_Effects): No action done for functions
+	returning class-wide types since it requires generating code using
+	'reference and the CCG target has no secondary stack.
+	* gnat1drv.adb: Disable building static dispatch tables when generating
+	C code.
+
 2018-01-11  Piotr Trojanek  <trojanek@adacore.com>
 
 	* libgnat/a-direio.ads, libgnat/a-sequio.ads, libgnat/a-ststio.ads,
diff --git a/gcc/ada/exp_util.adb b/gcc/ada/exp_util.adb
index 86b57dc..000dc1d 100644
--- a/gcc/ada/exp_util.adb
+++ b/gcc/ada/exp_util.adb
@@ -11174,6 +11174,16 @@ package body Exp_Util is
         and then Side_Effect_Free (Exp, Name_Req, Variable_Ref)
       then
          return;
+
+      --  Generating C code we cannot remove side effect of function returning
+      --  class-wide types since there is no secondary stack (required to use
+      --  'reference).
+
+      elsif Modify_Tree_For_C
+        and then Nkind (Exp) = N_Function_Call
+        and then Is_Class_Wide_Type (Etype (Exp))
+      then
+         return;
       end if;
 
       --  The remaining processing is done with all checks suppressed
diff --git a/gcc/ada/gnat1drv.adb b/gcc/ada/gnat1drv.adb
index eda994d..12ff49c 100644
--- a/gcc/ada/gnat1drv.adb
+++ b/gcc/ada/gnat1drv.adb
@@ -166,6 +166,7 @@ procedure Gnat1drv is
       if Generate_C_Code then
          Modify_Tree_For_C := True;
          Unnest_Subprogram_Mode := True;
+         Building_Static_Dispatch_Tables := False;
          Minimize_Expression_With_Actions := True;
          Expand_Nonbinary_Modular_Ops := True;