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 c/5354


Hello,

gcc doesn't correctly manage temporary stack slots under certain
circumstances. In this test case, it re-uses the same slot for 'temp1' as
for 'temp2'.

2002-02-14  Eric Botcazou <ebotcazou@multimania.com>

 PR c/5354:
 *c-common.c (c_expand_expr): preserve result
 of a statement expression if needed

--- gcc/c-common.c 9 Feb 2002 03:08:04 -0000 1.291
+++ gcc/c-common.c 14 Feb 2002 19:06:35 -0000
@@ -3457,6 +3457,7 @@
       {
  tree rtl_expr;
  rtx result;
+ int preserve_result = 0;

  /* Since expand_expr_stmt calls free_temp_slots after every
     expression statement, we must call push_temp_slots here.
@@ -3483,12 +3484,21 @@

      if (TREE_CODE (last) == SCOPE_STMT
   && TREE_CODE (expr) == EXPR_STMT)
-       TREE_ADDRESSABLE (expr) = 1;
+       {
+  TREE_ADDRESSABLE (expr) = 1;
+  preserve_result = 1;
+       }
    }

  expand_stmt (STMT_EXPR_STMT (exp));
  expand_end_stmt_expr (rtl_expr);
  result = expand_expr (rtl_expr, target, tmode, modifier);
+
+ /* If we want the result of this expression, we must preserve
+          its slot before deleting the temporaries.  */
+ if (preserve_result)
+   preserve_temp_slots (result);
+
  pop_temp_slots ();
  return result;
       }

/* PR c/5354 */
/* { dg-do run } */
/* { dg-options "" } */

/* Verify that GCC preserves relevant stack slots
   through stack unwinding */

extern void abort(void);
extern void exit(int);

int main()
{
  int fixed;

  fixed = ({ int temp1 = 2; temp1; }) - ({ int temp2 = 1; temp2; });

  if (fixed != 1)
    abort();

  exit(0);
}

--
Eric Botcazou
ebotcazou@multimania.com


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