This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C++ PATCH]: Fix bug 2936 (a regression)
- To: gcc-patches at gcc dot gnu dot org
- Subject: [C++ PATCH]: Fix bug 2936 (a regression)
- From: Nathan Sidwell <nathan at codesourcery dot com>
- Date: Wed, 30 May 2001 09:54:44 +0100
- CC: mark at codesourcery dot com
- Organization: Codesourcery LLC
Hi,
I've installed this obvious fix for bug 2936 which was a tree inlining
regression from 2.95.
Two bugs,
1) The VAR_DECL for a function scope anonymous union never had its
DECL_CONTEXT set.
2) When copying that decl for inlining we need to copy and duplicate the
DECL_ANON_UNION_ELEMS.
booted and tested on i686-pc-linux-gnu, installed on mainline & branch.
nathan
--
Dr Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery LLC
'But that's a lie.' - 'Yes it is. What's your point?'
nathan@codesourcery.com : http://www.cs.bris.ac.uk/~nathan/ : nathan@acm.org
2001-05-30 Nathan Sidwell <nathan@codesourcery.com>
PR g++/2936
* decl.c (finish_anon_union): Copy context.
* optimize.c (remap_decl): Remap anonymous aggregate members too.
2001-05-30 Nathan Sidwell <nathan@codesourcery.com>
* g++.old-deja/g++.other/optimize3.C: New file.
Index: cp/optimize.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/optimize.c,v
retrieving revision 1.51.2.18
diff -c -3 -p -r1.51.2.18 optimize.c
*** optimize.c 2001/05/23 02:08:54 1.51.2.18
--- optimize.c 2001/05/30 08:38:57
*************** static void update_cloned_parm PARAMS ((
*** 106,113 ****
decisions about when a function is too big to inline. */
#define INSNS_PER_STMT (10)
! /* Remap DECL during the copying of the BLOCK tree for the function.
! DATA is really an `inline_data *'. */
static tree
remap_decl (decl, id)
--- 106,112 ----
decisions about when a function is too big to inline. */
#define INSNS_PER_STMT (10)
! /* Remap DECL during the copying of the BLOCK tree for the function. */
static tree
remap_decl (decl, id)
*************** remap_decl (decl, id)
*** 149,154 ****
--- 148,173 ----
copy_body_r, id, NULL);
}
+ if (!DECL_NAME (t) && TREE_TYPE (t)
+ && ANON_AGGR_TYPE_P (TREE_TYPE ((t))))
+ {
+ /* For a VAR_DECL of anonymous type, we must also copy the
+ member VAR_DECLS here and rechain the
+ DECL_ANON_UNION_ELEMS. */
+ tree members = NULL;
+ tree src;
+
+ for (src = DECL_ANON_UNION_ELEMS (t); src;
+ src = TREE_CHAIN (src))
+ {
+ tree member = remap_decl (TREE_VALUE (src), id);
+
+ my_friendly_assert (!TREE_PURPOSE (src), 20010529);
+ members = tree_cons (NULL, member, members);
+ }
+ DECL_ANON_UNION_ELEMS (t) = nreverse (members);
+ }
+
/* Remember it, so that if we encounter this local entity
again we can reuse this copy. */
n = splay_tree_insert (id->decl_map,
Index: testsuite/g++.old-deja/g++.other/optimize3.C
===================================================================
RCS file: optimize3.C
diff -N optimize3.C
*** /dev/null Tue May 5 13:32:27 1998
--- optimize3.C Wed May 30 01:39:00 2001
***************
*** 0 ****
--- 1,38 ----
+ // Special g++ Options: -O2
+ //
+ // Copyright (C) 2001 Free Software Foundation, Inc.
+ // Contributed by Nathan Sidwell 29 May 2001 <nathan@codesourcery.com>
+
+ // Bug 2936. We ICE'd on tree inlining a function with an anonymous
+ // union decl.
+
+ inline const unsigned char *Foo (const char *string)
+ {
+ union
+ {
+ const char *p1;
+ const unsigned char *p2;
+ };
+ p1 = 0;
+ p2 = 0;
+
+
+ p1 = string;
+ return p2;
+
+ }
+
+ const unsigned char *Baz (const char *string)
+ {
+ return Foo (string);
+ }
+
+ int main ()
+ {
+ const char *string = "s";
+ const unsigned char *result;
+
+ result = Baz (string);
+ return (static_cast <const void *> (result)
+ != static_cast <const void *> (string));
+ }