[PATCH] Don't throw away DECL_RTL in C merge_decls, fix PA encode_section_info (PR bootstrap/34003)
Jakub Jelinek
jakub@redhat.com
Fri Dec 14 19:07:00 GMT 2007
Hi!
Dan's tree union reorganization patch
http://gcc.gnu.org/ml/gcc-patches/2005-06/msg02029.html
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-decl.c.diff?cvsroot=gcc&r1=1.674&r2=1.675
removed COPY_DECL_RTL in C merge_decls, so now duplicate_decls always throws
rtls on the floor and leaves them to be recreated again if needed.
I didn't find any such intent in that patch. merge_decls still has
/* If OLDDECL had its DECL_RTL instantiated, re-invoke make_decl_rtl
so that encode_section_info has a chance to look at the new decl
flags and attributes. */
if (DECL_RTL_SET_P (olddecl)
&& (TREE_CODE (olddecl) == FUNCTION_DECL
|| (TREE_CODE (olddecl) == VAR_DECL
&& TREE_STATIC (olddecl))))
make_decl_rtl (olddecl);
chunk at the end, but because of the missed COPY_DECL_RTL and as
this is after memcpy from newdecl to olddecl, this can't ever hit
(DECL_RTL_SET_P will be always false). While for most targets this
is just an compile time pessimization, the rtl needs to be recreated,
on PA with its SYMBOL_FLAG_REFERENCED it means that flag is lost during
this and so in -fno-unit-at-a-time
extern void foo (void);
int bar (void) { foo (); return 1; }
extern void foo (void);
foo is not considered referenced, which leads to .IMPORT foo,CODE directive
omission, and leads to linker errors. So, gcc-4.3 can't be bootstrapped
with gcc-4.3 on hppa-hpux, because first stage is built at -O0. In addition
to the c-decl.c fix I had to also fix pa_encode_section_info to preserve
that flag if !first.
I have bootstrapped/regtested this on x86_64-linux and i686-linux, ok for
trunk if somebody (Dave, the reporter, ...) tests it on hppa-hpux?
2007-12-14 Jakub Jelinek <jakub@redhat.com>
PR bootstrap/34003
* c-decl.c (merge_decls): Copy RTL from olddecl to newdecl.
* config/pa/pa.c (pa_encode_section_info): If !first, preserve
SYMBOL_FLAG_REFERENCED flag.
* gcc.dg/pr34003-1.c: New test.
* gcc.dg/pr34003-2.c: New.
--- gcc/c-decl.c.jj 2007-11-26 22:14:08.000000000 +0100
+++ gcc/c-decl.c 2007-12-13 20:11:33.000000000 +0100
@@ -1670,6 +1670,9 @@ merge_decls (tree newdecl, tree olddecl,
}
}
+ /* Keep the old rtl since we can safely use it. */
+ if (HAS_RTL_P (olddecl))
+ COPY_DECL_RTL (olddecl, newdecl);
/* Merge the type qualifiers. */
if (TREE_READONLY (newdecl))
--- gcc/config/pa/pa.c.jj 2007-12-13 18:56:21.000000000 +0100
+++ gcc/config/pa/pa.c 2007-12-13 20:32:04.000000000 +0100
@@ -7834,6 +7834,12 @@ hppa_encode_label (rtx sym)
static void
pa_encode_section_info (tree decl, rtx rtl, int first)
{
+ int old_referenced = 0;
+
+ if (!first && MEM_P (rtl) && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF)
+ old_referenced
+ = SYMBOL_REF_FLAGS (XEXP (rtl, 0)) & SYMBOL_FLAG_REFERENCED;
+
default_encode_section_info (decl, rtl, first);
if (first && TEXT_SPACE_P (decl))
@@ -7842,6 +7848,8 @@ pa_encode_section_info (tree decl, rtx r
if (TREE_CODE (decl) == FUNCTION_DECL)
hppa_encode_label (XEXP (rtl, 0));
}
+ else if (old_referenced)
+ SYMBOL_REF_FLAGS (XEXP (rtl, 0)) |= old_referenced;
}
/* This is sort of inverse to pa_encode_section_info. */
--- gcc/testsuite/gcc.dg/pr34003-1.c.jj 2007-12-13 21:07:51.000000000 +0100
+++ gcc/testsuite/gcc.dg/pr34003-1.c 2007-12-13 21:07:15.000000000 +0100
@@ -0,0 +1,8 @@
+/* PR bootstrap/34003 */
+/* { dg-do link } */
+/* { dg-options "-O0" } */
+/* { dg-additional-sources "pr34003-2.c" } */
+
+extern void foo (void);
+int bar (void) { foo (); return 1; }
+extern void foo (void);
--- gcc/testsuite/gcc.dg/pr34003-2.c.jj 2007-12-13 21:07:59.000000000 +0100
+++ gcc/testsuite/gcc.dg/pr34003-2.c 2007-12-13 21:09:35.000000000 +0100
@@ -0,0 +1,20 @@
+/* PR bootstrap/34003 */
+/* { dg-do compile } */
+/* { dg-options "-O0" } */
+
+extern void abort (void);
+
+int seen = 0;
+
+void foo (void)
+{
+ ++seen;
+}
+
+int main (void)
+{
+ extern int bar (void);
+ if (bar () != 1 || seen != 1)
+ abort ();
+ return 0;
+}
Jakub
More information about the Gcc-patches
mailing list