https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83905

            Bug ID: 83905
           Summary: ix86_expand_epilogue modifies the copy of
                    cfun->machine->frame
           Product: gcc
           Version: 8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hjl.tools at gmail dot com
                CC: mliska at suse dot cz, ubizjak at gmail dot com
  Target Milestone: ---
            Target: x86

Created attachment 43155
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=43155&action=edit
A patch to demonstrate the ix86_expand_epilogue issue

With the patch in this bug report:

Subject: [PATCH] i386: More use reference of struct ix86_frame to avoid copy

When there is no need to make a copy of ix86_frame, we can use reference
of struct ix86_frame to avoid copy.

        * config/i386/i386.c (ix86_expand_prologue): Use reference of
        struct ix86_frame.
        (ix86_expand_epilogue): Likewise.

I got

raised STORAGE_ERROR : stack overflow or erroneous memory access
make[5]: *** [/export/gnu/import/git/sources/gcc/gcc/ada/Make-generated.in:45:
a
da/sinfo.h] Error 1

on trunk when bootstrapping GCC with ada on x86-64.  Revert the change
in ix86_expand_epilogue:

diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index bfb31db8752..9eba3ffd5d6 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -14291,7 +14290,6 @@ ix86_expand_epilogue (int style)
 {
   struct machine_function *m = cfun->machine;
   struct machine_frame_state frame_state_save = m->fs;
-  struct ix86_frame frame;
   bool restore_regs_via_mov;
   bool using_drap;
   bool restore_stub_is_tail = false;
@@ -14304,7 +14302,7 @@ ix86_expand_epilogue (int style)
     }

   ix86_finalize_stack_frame_flags ();
-  frame = m->frame;
+  struct ix86_frame &frame = cfun->machine->frame;

   m->fs.sp_realigned = stack_realign_fp;
   m->fs.sp_valid = stack_realign_fp

fixed GCC bootstrap.  ix86_expand_epilogue has

  /* Special care must be taken for the normal return case of a function
     using eh_return: the eax and edx registers are marked as saved, but
     not restored along this path.  Adjust the save location to match.  */
  if (crtl->calls_eh_return && style != 2)
    frame.reg_save_offset -= 2 * UNITS_PER_WORD;

It works only if "frame" is a copy, not a reference to cfun->machine->frame.

Reply via email to