From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17518 invoked by alias); 4 Mar 2005 23:22:44 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 17497 invoked by alias); 4 Mar 2005 23:22:37 -0000 Date: Fri, 04 Mar 2005 23:22:00 -0000 Message-ID: <20050304232237.17496.qmail@sourceware.org> From: "aoliva at redhat dot com" To: gcc-bugs@gcc.gnu.org In-Reply-To: <20050220111234.20103.falk@debian.org> References: <20050220111234.20103.falk@debian.org> Reply-To: gcc-bugzilla@gcc.gnu.org Subject: [Bug c++/20103] [4.0/4.1 regression] ICE in create_tmp_var with C99 style struct initializer X-Bugzilla-Reason: CC X-SW-Source: 2005-03/txt/msg00593.txt.bz2 List-Id: ------- Additional Comments From aoliva at gcc dot gnu dot org 2005-03-04 23:22 ------- Subject: Re: [PR c++/20103] failure to gimplify constructors for addressable types On Mar 3, 2005, Andrew Pinski wrote: > I think this is the wrong approach. The front-end and not > the gimplifier should be creating these temporaries, I mentioned > this already in the bug. How about this? I tried with the TARGET_EXPR by itself, but it failed to be recognized as an lvalue, so I introduced the compound expr. Testing on x86_64-linux-gnu. Ok to install if it passes? Index: gcc/cp/ChangeLog from Alexandre Oliva PR c++/20103 * semantics.c (finish_compound_literal): Ensure the result is an lvalue, by creating a compound-expr with a target-expr and its decl. Index: gcc/cp/semantics.c =================================================================== RCS file: /cvs/gcc/gcc/gcc/cp/semantics.c,v retrieving revision 1.463 diff -u -p -r1.463 semantics.c --- gcc/cp/semantics.c 23 Feb 2005 05:30:48 -0000 1.463 +++ gcc/cp/semantics.c 4 Mar 2005 23:17:50 -0000 @@ -1996,7 +1996,11 @@ finish_compound_literal (tree type, tree complete_array_type (type, compound_literal, 1); } - return compound_literal; + /* A compound-literal is an lvalue in C, so make it so in C++ as + well. */ + compound_literal = get_target_expr (compound_literal); + return build2 (COMPOUND_EXPR, TREE_TYPE (compound_literal), + compound_literal, TARGET_EXPR_SLOT (compound_literal)); } /* Return the declaration for the function-name variable indicated by Index: gcc/testsuite/ChangeLog from Alexandre Oliva * g++.dg/tree-ssa/pr20103.C: New. Index: gcc/testsuite/g++.dg/tree-ssa/pr20103.C =================================================================== RCS file: gcc/testsuite/g++.dg/tree-ssa/pr20103.C diff -N gcc/testsuite/g++.dg/tree-ssa/pr20103.C --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gcc/testsuite/g++.dg/tree-ssa/pr20103.C 4 Mar 2005 23:18:05 -0000 @@ -0,0 +1,34 @@ +// PR c++/20103 + +// { dg-do compile } + +// { dg-options "" } + +// Gimplification used to fail for (B){x}, because create_tmp_var +// required a non-addressable type, and we didn't wrap the constructor +// in a target_expr, ensuring it's taken as an lvalue. + +struct A +{ + A(const A&); +}; + +struct B +{ + A a; +}; + +void foo(B); +void bar(B&); +void bap(B*); + +void baz(A &x) +{ + foo ((B){x}); + bar ((B){x}); + bap (&(B){x}); + + foo ((const B&)(B){x}); + bar ((B&)(B){x}); + bap (&(B&)(B){x}); +} -- Alexandre Oliva http://www.ic.unicamp.br/~oliva/ Red Hat Compiler Engineer aoliva@{redhat.com, gcc.gnu.org} Free Software Evangelist oliva@{lsd.ic.unicamp.br, gnu.org} -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20103