This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix PR middle-end/35136


This is a very recent regression present on the mainline at -O.  The compiler 
stops because of an unexpected variable in the middle of the SSA stream:

adr.adb:19:04: warning: variable "A" is read but never assigned
adr.adb: In function 'ADR':
adr.adb:5: error: expected an SSA_NAME object
adr.adb:5: error: in statement
# A.36 = VDEF <A.36> { A.36 }
A.36 = D.375_38;

The failure mode is as follows: IVOPTS decices to turn the iteration on the
value of A (variable in the code) to an iteration on its address.  But there
is a cast in the middle

  a.0_4 = (system__aux_dec__TsaB) a_3(D);
  D.249_5 = i_131 + a.0_4;

so create_iv invokes force_gimple_operand on ADDR_EXPR<NOP_EXPR<SSA_NAME>>,
which is passed to gnat_gimplify_expr.  The latter creates the temporary
A.36 and it is never marked for renaming.

Note that there is a similar temporary created later in the code

  D.379_8 = (system__aux_dec__TsaB) a_3(D);
  A.38 = D.379_8;
  D.380_1 = &A.38 + 2;

but it is properly marked for renaming because force_gimple_operand_bsi is 
invoked instead of force_gimple_operand.

Hence the fix, bootstrapped/regtested on i586-suse-linux, OK for mainline?


2008-02-12  Eric Botcazou  <ebotcazou@adacore.com>

	PR middle-end/35136
	* force_gimple_operand (force_gimple_operand_bsi): Move SSA renaming
	code from here to...
	(force_gimple_operand): ...here.


2008-02-12  Eric Botcazou  <ebotcazou@adacore.com>

        * gnat.dg/loop_address.adb: New test.


-- 
Eric Botcazou
Index: gimplify.c
===================================================================
--- gimplify.c	(revision 132243)
+++ gimplify.c	(working copy)
@@ -6629,6 +6629,14 @@ force_gimple_operand (tree expr, tree *s
 
   pop_gimplify_context (NULL);
 
+  if (*stmts && gimple_in_ssa_p (cfun))
+    {
+      tree_stmt_iterator tsi;
+
+      for (tsi = tsi_start (*stmts); !tsi_end_p (tsi); tsi_next (&tsi))
+	mark_symbols_for_renaming (tsi_stmt (tsi));
+    }
+
   return expr;
 }
 
@@ -6648,14 +6656,6 @@ force_gimple_operand_bsi (block_stmt_ite
   expr = force_gimple_operand (expr, &stmts, simple_p, var);
   if (stmts)
     {
-      if (gimple_in_ssa_p (cfun))
-	{
-	  tree_stmt_iterator tsi;
-
-	  for (tsi = tsi_start (stmts); !tsi_end_p (tsi); tsi_next (&tsi))
-	    mark_symbols_for_renaming (tsi_stmt (tsi));
-	}
-
       if (before)
 	bsi_insert_before (bsi, stmts, m);
       else
-- { dg-do compile }
-- { dg-options "-O -gnatws" }

-- PR middle-end/35136

pragma Extend_System(AUX_DEC);
with System;

procedure Loop_Address is

   function Y(E : Integer) return String is
   begin
      return "";
   end Y;

   function X(C : in System.Address) return String is
      D : Integer;
      for D use at C;
   begin
      return Y(D);
   end X;

   A : System.Address;
   B : String := "";

begin
   for I in 0..1 loop
      B := X(System."+"(A, I));
   end loop;
end;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]