This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/20103] [4.0/4.1 regression] ICE in create_tmp_var with C99 style struct initializer
- From: "aoliva at redhat dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 3 Mar 2005 07:42:19 -0000
- Subject: [Bug c++/20103] [4.0/4.1 regression] ICE in create_tmp_var with C99 style struct initializer
- References: <20050220111234.20103.falk@debian.org>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Additional Comments From aoliva at gcc dot gnu dot org 2005-03-03 07:42 -------
Subject: [PR c++/20103] failure to gimplify constructors for addressable types
In the reduced testcase from the bug report, included in the patch
file below, we fail to gimplify the CONSTRUCTOR created for the
compound-literal expression. When we attempt to create_tmp_var to
hold the B-typed value, it fails because B is addressable.
This patch introduces an alternate entry point for create_tmp_var that
accepts addressable types, and uses that in the relevant caller when
the value is a CONSTRUCTOR.
Bootstrapping on x86_64-linux-gnu, after successful C++ regression
testing on make all. Ok to install if full bootstrap and regression
testing completes?
Index: gcc/gimplify.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/gimplify.c,v
retrieving revision 2.113
diff -u -p -r2.113 gimplify.c
--- gcc/gimplify.c 18 Feb 2005 19:35:37 -0000 2.113
+++ gcc/gimplify.c 3 Mar 2005 07:40:02 -0000
@@ -356,15 +356,13 @@ create_tmp_var_raw (tree type, const cha
only from gimplification or optimization, at which point the creation of
certain types are bugs. */
-tree
-create_tmp_var (tree type, const char *prefix)
+static tree
+create_tmp_var_maybe_addressable (tree type, const char *prefix)
{
tree tmp_var;
- /* We don't allow types that are addressable (meaning we can't make copies),
- incomplete, or of variable size. */
- gcc_assert (!TREE_ADDRESSABLE (type)
- && COMPLETE_TYPE_P (type)
+ /* We don't allow types that are incomplete, or of variable size. */
+ gcc_assert (COMPLETE_TYPE_P (type)
&& TREE_CODE (TYPE_SIZE_UNIT (type)) == INTEGER_CST);
tmp_var = create_tmp_var_raw (type, prefix);
@@ -372,6 +370,18 @@ create_tmp_var (tree type, const char *p
return tmp_var;
}
+
+/* Like create_tmp_var_maybe_addressable, but make sure the given type
+ is NOT addressable. */
+
+tree
+create_tmp_var (tree type, const char *prefix)
+{
+ gcc_assert (!TREE_ADDRESSABLE (type));
+
+ return create_tmp_var_maybe_addressable (type, prefix);
+}
+
/* Given a tree, try to return a useful variable name that we can use
to prefix a temporary that is being assigned the value of the tree.
I.E. given <temp> = &A, return A. */
@@ -404,6 +414,9 @@ get_name (tree t)
static inline tree
create_tmp_from_val (tree val)
{
+ if (TREE_CODE (val) == CONSTRUCTOR)
+ return create_tmp_var_maybe_addressable (TREE_TYPE (val), get_name (val));
+
return create_tmp_var (TREE_TYPE (val), get_name (val));
}
Index: gcc/testsuite/ChangeLog
from Alexandre Oliva <aoliva@redhat.com>
* 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 3 Mar 2005 07:40:16 -0000
@@ -0,0 +1,25 @@
+// PR c++/20103
+
+// { dg-do compile }
+
+// { dg-options "" }
+
+// Gimplification used to fail for (B){x}, because create_tmp_var
+// required a non-addressable type.
+
+struct A
+{
+ A(const A&);
+};
+
+struct B
+{
+ A a;
+};
+
+void foo(B);
+
+void bar(A &x)
+{
+ foo((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