FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Debian > Debian GCC

 
 
LinkBack Thread Tools
 
Old 01-11-2012, 02:57 PM
"rguenth at gcc dot gnu.org"
 
Default ICE with variably sized types returned from nested functions

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

Richard Guenther <rguenth at gcc dot gnu.org> changed:

What |Removed |Added
----------------------------------------------------------------------------
Keywords|ice-on-valid-code |accepts-invalid,
| |ice-on-invalid-code
Component|middle-end |c
Summary|ICE with variably sized |ICE with variably sized
|types and nested functions |types returned from nested
| |functions
Known to fail| |4.7.0

--- Comment #23 from Richard Guenther <rguenth at gcc dot gnu.org> 2012-01-11 15:57:03 UTC ---
In PR21374 it was decided to reject the testcase which makes this a C frontend
issue. Testcase that still ICEs on the trunk even when optimizing:

int
main (int argc, char **argv)
{
int size = 10;
typedef struct
{
char val[size];
}
block;
block b;
block __attribute__((noinline))
retframe_block ()
{
return *(block *) &b;
}
b=retframe_block ();
return 0;
}

as alternative to rejecting this case we can lower returning variable-size
types during un-nesting to explicit passing of a return slot and using
memcpy, making the nested function return nothing.

--
Configure bugmail: http://gcc.gnu.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


--
To UNSUBSCRIBE, email to debian-gcc-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: http://lists.debian.org/bug-8081-5724-uwLosBFgFd@http.gcc.gnu.org/bugzilla/
 
Old 01-12-2012, 09:23 AM
"rguenth at gcc dot gnu.org"
 
Default ICE with variably sized types returned from nested functions

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

--- Comment #24 from Richard Guenther <rguenth at gcc dot gnu.org> 2012-01-12 10:23:05 UTC ---
Created attachment 26306
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=26306
A patch for using by-reference passing

(In reply to comment #23)
> as alternative to rejecting this case we can lower returning variable-size
> types during un-nesting to explicit passing of a return slot and using
> memcpy, making the nested function return nothing.

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).

--
Configure bugmail: http://gcc.gnu.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


--
To UNSUBSCRIBE, email to debian-gcc-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: http://lists.debian.org/bug-8081-5724-OVo6X5UDgt@http.gcc.gnu.org/bugzilla/
 
Old 01-12-2012, 09:24 AM
"rguenth at gcc dot gnu.org"
 
Default ICE with variably sized types returned from nested functions

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

Richard Guenther <rguenth at gcc dot gnu.org> changed:

What |Removed |Added
----------------------------------------------------------------------------
CC| |jsm28 at gcc dot gnu.org

--
Configure bugmail: http://gcc.gnu.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


--
To UNSUBSCRIBE, email to debian-gcc-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: http://lists.debian.org/bug-8081-5724-hqvAGsloVb@http.gcc.gnu.org/bugzilla/
 
Old 01-12-2012, 09:24 AM
"rguenth at gcc dot gnu.org"
 
Default ICE with variably sized types returned from nested functions

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

Richard Guenther <rguenth at gcc dot gnu.org> changed:

What |Removed |Added
----------------------------------------------------------------------------
CC| |rguenth at gcc dot gnu.org

--
Configure bugmail: http://gcc.gnu.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


--
To UNSUBSCRIBE, email to debian-gcc-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: http://lists.debian.org/bug-8081-5724-DZkgcEbOV3@http.gcc.gnu.org/bugzilla/
 
Old 01-13-2012, 07:36 AM
"ebotcazou at gcc dot gnu.org"
 
Default ICE with variably sized types returned from nested functions

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.

--
Configure bugmail: http://gcc.gnu.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


--
To UNSUBSCRIBE, email to debian-gcc-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: http://lists.debian.org/bug-8081-5724-pOoAQrH4oB@http.gcc.gnu.org/bugzilla/
 
Old 01-13-2012, 08:08 AM
"rguenther at suse dot de"
 
Default ICE with variably sized types returned from nested functions

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.

--
Configure bugmail: http://gcc.gnu.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


--
To UNSUBSCRIBE, email to debian-gcc-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: http://lists.debian.org/bug-8081-5724-z3n43N1X2g@http.gcc.gnu.org/bugzilla/
 
Old 01-13-2012, 09:11 AM
"rguenth at gcc dot gnu.org"
 
Default ICE with variably sized types returned from nested functions

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

--- Comment #27 from Richard Guenther <rguenth at gcc dot gnu.org> 2012-01-13 10:11:43 UTC ---
(In reply to comment #26)
> 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.

OTOH as GIMPLE cannot deal with VLAs on the LHS of a CALL when not applying RSO
the above is correct anyway.

--
Configure bugmail: http://gcc.gnu.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


--
To UNSUBSCRIBE, email to debian-gcc-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: http://lists.debian.org/bug-8081-5724-p5Ecn23yIC@http.gcc.gnu.org/bugzilla/
 
Old 01-13-2012, 10:21 AM
"ebotcazou at gcc dot gnu.org"
 
Default ICE with variably sized types returned from nested functions

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

--- Comment #28 from Eric Botcazou <ebotcazou at gcc dot gnu.org> 2012-01-13 11:21:34 UTC ---
> OTOH as GIMPLE cannot deal with VLAs on the LHS of a CALL when not applying RSO
> the above is correct anyway.

Right, gimplify_return_expr already has a similar provision:

else if (aggregate_value_p (result_decl, TREE_TYPE (current_function_decl)))
{
if (TREE_CODE (DECL_SIZE (result_decl)) != INTEGER_CST)
{
if (!TYPE_SIZES_GIMPLIFIED (TREE_TYPE (result_decl)))
gimplify_type_sizes (TREE_TYPE (result_decl), pre_p);
/* Note that we don't use gimplify_vla_decl because the RESULT_DECL
should be effectively allocated by the caller, i.e. all calls to
this function must be subject to the Return Slot Optimization. */
gimplify_one_sizepos (&DECL_SIZE (result_decl), pre_p);
gimplify_one_sizepos (&DECL_SIZE_UNIT (result_decl), pre_p);
}
result = result_decl;
}

--
Configure bugmail: http://gcc.gnu.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


--
To UNSUBSCRIBE, email to debian-gcc-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: http://lists.debian.org/bug-8081-5724-iCSwu9htQX@http.gcc.gnu.org/bugzilla/
 
Old 01-13-2012, 10:50 AM
"rguenth at gcc dot gnu.org"
 
Default ICE with variably sized types returned from nested functions

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

Richard Guenther <rguenth at gcc dot gnu.org> changed:

What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |ASSIGNED
AssignedTo|unassigned at gcc dot |rguenth at gcc dot gnu.org
|gnu.org |

--- Comment #29 from Richard Guenther <rguenth at gcc dot gnu.org> 2012-01-13 11:50:10 UTC ---
Mine.

--
Configure bugmail: http://gcc.gnu.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


--
To UNSUBSCRIBE, email to debian-gcc-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: http://lists.debian.org/bug-8081-5724-sEHSJNWRJh@http.gcc.gnu.org/bugzilla/
 
Old 01-13-2012, 11:05 AM
"rguenth at gcc dot gnu.org"
 
Default ICE with variably sized types returned from nested functions

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

--- Comment #30 from Richard Guenther <rguenth at gcc dot gnu.org> 2012-01-13 12:05:32 UTC ---
Author: rguenth
Date: Fri Jan 13 12:05:27 2012
New Revision: 183153

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=183153
Log:
2012-01-13 Richard Guenther <rguenther@suse.de>

PR middle-end/8081
* gimplify.c (gimplify_modify_expr_rhs): For calls with a
variable-sized result always use RSO.

* gcc.dg/torture/pr8081.c: New testcase.

Added:
trunk/gcc/testsuite/gcc.dg/torture/pr8081.c
Modified:
trunk/gcc/ChangeLog
trunk/gcc/gimplify.c
trunk/gcc/testsuite/ChangeLog

--
Configure bugmail: http://gcc.gnu.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


--
To UNSUBSCRIBE, email to debian-gcc-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: http://lists.debian.org/bug-8081-5724-bpnqa2Hngz@http.gcc.gnu.org/bugzilla/
 

Thread Tools




All times are GMT. The time now is 08:51 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org