------- 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 <[EMAIL PROTECTED]> 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  <[EMAIL PROTECTED]>

        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  <[EMAIL PROTECTED]>

        * 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   [EMAIL PROTECTED], gcc.gnu.org}
Free Software Evangelist  [EMAIL PROTECTED], gnu.org}


-- 


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

Reply via email to