public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "rguenther at suse dot de" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/8081] ICE with variably sized types returned from nested functions
Date: Fri, 13 Jan 2012 09:28:00 -0000	[thread overview]
Message-ID: <bug-8081-4-V2zKoPKyLE@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-8081-4@http.gcc.gnu.org/bugzilla/>

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=8081

--- Comment #26 from rguenther at suse dot de <rguenther at suse dot de> 2012-01-13 09:08:30 UTC ---
On Fri, 13 Jan 2012, ebotcazou at gcc dot gnu.org wrote:

> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=8081
> 
> Eric Botcazou <ebotcazou at gcc dot gnu.org> changed:
> 
>            What    |Removed                     |Added
> ----------------------------------------------------------------------------
>                  CC|                            |ebotcazou at gcc dot
>                    |                            |gnu.org
> 
> --- Comment #25 from Eric Botcazou <ebotcazou at gcc dot gnu.org> 2012-01-13 08:36:56 UTC ---
> > It's of course not that easy as we gimplify before un-nesting.  The frontend
> > would be responsible to arrange things that way, similar to how we pass
> > a return slot in the C++ frontend (DECL_BY_REFERENCE on the DECL_RESULT
> > variable).  Like for the attached patch.  Passes
> > 
> > extern void abort (void);
> > int
> > main (int argc, char **argv)
> > {
> >   int size = 10;
> >   typedef struct
> >     {
> >       char val[size];
> >     }
> >   block;
> >   block a, b;
> >   block __attribute__((noinline))
> >   retframe_block ()
> >     {
> >       return *(block *) &b;
> >     }
> >   b.val[0] = -1;
> >   b.val[1] = -2;
> >   a=retframe_block ();
> >   if (a.val[0] != -1
> >       || a.val[1] != -2)
> >     abort ();
> >   return 0;
> > }
> > 
> > I'm not sure if one can construct a testcase where using return-slot
> > optimization causes wrong-code generation.  Alternatively checking
> > DECL_BY_REFERENCE on the callees DECL_RESULT instead of applying it to
> > all VLA types could work (though not for indirect calls).
> 
> You should ask specialists. :-)  In Ada, we do this routinely and the strategy
> used is that of the "forced RSO": we generate INIT_EXPR instead of MODIFY_EXPR
> and we create an explicit temporary if we detect potential overlap.
> 
> Btw, I don't understand why you're mixing DECL_BY_REFERENCE and RSO here, just
> 
> Index: gimplify.c
> ===================================================================
> --- gimplify.c  (revision 183104)
> +++ gimplify.c  (working copy)
> @@ -4417,6 +4417,9 @@ gimplify_modify_expr_rhs (tree *expr_p,
>                 /* It's OK to use the target directly if it's being
>                    initialized. */
>                 use_target = true;
> +             else if (variably_modified_type_p (TREE_TYPE (*to_p), NULL_TREE))
> +               /* Always use the target for variable-sized types.  */
> +               use_target = true;
>               else if (TREE_CODE (*to_p) != SSA_NAME
>                       && (!is_gimple_variable (*to_p)
>                           || needs_to_live_in_memory (*to_p)))
> 
> works for me on the testcase.

Ah, ok.  So I suppose the Frontend could force RSO here as well by
just setting CALL_EXPR_RETURN_SLOT_OPT on the CALL_EXPR.  Not sure
which approach is better.


  parent reply	other threads:[~2012-01-13  9:11 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <bug-8081-4@http.gcc.gnu.org/bugzilla/>
2012-01-11 15:56 ` [Bug middle-end/8081] ICE with variably sized types and " rguenth at gcc dot gnu.org
2012-01-11 15:58 ` [Bug c/8081] ICE with variably sized types returned from " rguenth at gcc dot gnu.org
2012-01-12 10:23 ` rguenth at gcc dot gnu.org
2012-01-13  8:55 ` ebotcazou at gcc dot gnu.org
2012-01-13  9:28 ` rguenther at suse dot de [this message]
2012-01-13 10:19 ` rguenth at gcc dot gnu.org
2012-01-13 11:37 ` ebotcazou at gcc dot gnu.org
2012-01-13 11:54 ` rguenth at gcc dot gnu.org
2012-01-13 12:08 ` rguenth at gcc dot gnu.org
2012-01-13 12:10 ` rguenth at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-8081-4-V2zKoPKyLE@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).