This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Candidate fix for PR c/7353
- From: Zack Weinberg <zack at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Mon, 7 Oct 2002 16:52:25 -0700
- Subject: Candidate fix for PR c/7353
PR c/7353, distilled, reports that
typedef A = 0; /* equivalent to 'typedef int A;' */
produces an ICE with all versions of GCC since 3.0. This is an
obscure, rarely-used extension, but if we're going to have it, it
should work.
There are two bugs. One is that make_decl_rtl is being called on a
TYPE_DECL; it quite properly aborts. The other is that the code for
handling 'typedef T = expr' was not updated when DECL_ORIGINAL_TYPE
was invented, so we abort in gen_typedef_die.
I believe this patch fixes the bug. I have one remaining concern:
given
typedef A = 0;
A a;
gdb reports
(gdb) ptype a
type = int
Shouldn't that be type = A? It does do the same thing for
typedef int B;
B b;
so perhaps this is as intended.
zw
* c-decl.c (finish_decl): When processing 'typedef T = expr',
TREE_TYPE (T) should be a copy of TREE_TYPE (expr), as is done
for normal typedefs.
* toplev.c (rest_of_decl_compilation): Do not call
make_decl_rtl on TYPE_DECLs.
===================================================================
Index: c-decl.c
--- c-decl.c 22 Sep 2002 02:03:14 -0000 1.350
+++ c-decl.c 7 Oct 2002 23:45:48 -0000
@@ -2994,7 +2994,8 @@ finish_decl (decl, init, asmspec_tree)
else
{
/* typedef foo = bar; store the type of bar as the type of foo. */
- TREE_TYPE (decl) = TREE_TYPE (init);
+ TREE_TYPE (decl) = build_type_copy (TREE_TYPE (init));
+ DECL_ORIGINAL_TYPE (decl) = TREE_TYPE (init);
DECL_INITIAL (decl) = init = 0;
}
}
===================================================================
Index: toplev.c
--- toplev.c 7 Oct 2002 03:01:39 -0000 1.679
+++ toplev.c 7 Oct 2002 23:45:52 -0000
@@ -2272,8 +2272,9 @@ rest_of_decl_compilation (decl, asmspec,
/* Forward declarations for nested functions are not "external",
but we need to treat them as if they were. */
- if (TREE_STATIC (decl) || DECL_EXTERNAL (decl)
- || TREE_CODE (decl) == FUNCTION_DECL)
+ if (TREE_CODE (decl) == FUNCTION_DECL
+ || (TREE_CODE (decl) == VAR_DECL
+ && (TREE_STATIC (decl) || DECL_EXTERNAL (decl))))
{
timevar_push (TV_VARCONST);