This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
PATCH [mainline] fix -combine bug for parser, gzip of 2000 SPEC benchmark
- From: Fariborz Jahanian <fjahanian at apple dot com>
- To: "gcc-patches at gcc dot gnu dot org Patches" <gcc-patches at gcc dot gnu dot org>
- Cc: Fariborz Jahanian <fjahanian at apple dot com>
- Date: Wed, 29 Sep 2004 08:51:08 -0700
- Subject: PATCH [mainline] fix -combine bug for parser, gzip of 2000 SPEC benchmark
Following patch fixes an IMA bug in two SPEC 2000 benchmarks, parser
and gzip. Without this patch
both programs mis-compare. This patch, along with RTH's patch for
PR/17531 (needed to prevent
ICEing of gzip), was tested successfully in building SPEC benchmarks in
IMA mode (-combine)
for apple-ppc-darwin platform. Patch has been bootstrapped, dejagnu
tested on apple-ppc-darwin.
Problem can be reproduced in a trivial test case using -combine only.
Issued
warning tells the whole story.
% cat a.h
#define MAX_WORD 60
extern int sentence[];
% cat a.c
#include "a.h"
% cat main.c
#include "a.h"
int sentence[MAX_WORD];
% cat b.c
#include "a.h"
% mygccm5o -combine a.c main.c b.c -c
a.h:3: warning: array 'sentence' assumed to have one element
OK for FSF mainline?
- Fariborz (fjahanian@apple.com)
ChangeLog:
2004-09-29 Fariborz Jahanian <fjahanian@apple.com>
* c-decl.c (merge_decls): Preserve OLDDECL's size if newdecl is
in another TU and its size is unspecified.
Index: c-decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-decl.c,v
retrieving revision 1.589
diff -c -p -r1.589 c-decl.c
*** c-decl.c 24 Sep 2004 17:22:17 -0000 1.589
--- c-decl.c 29 Sep 2004 15:49:03 -0000
*************** merge_decls (tree newdecl, tree olddecl,
*** 1517,1522 ****
--- 1517,1523 ----
{
int new_is_definition = (TREE_CODE (newdecl) == FUNCTION_DECL
&& DECL_INITIAL (newdecl) != 0);
+ bool preserve_old_decl_size = false;
/* For real parm decl following a forward decl, rechain the old decl
in its new location and clear TREE_ASM_WRITTEN (it's not a
*************** merge_decls (tree newdecl, tree olddecl,
*** 1654,1659 ****
--- 1655,1666 ----
TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl);
if (! DECL_EXTERNAL (newdecl))
{
+ /* Preserve OLDDECL's size if newdecl is in
+ another TU and its size is unspecified. */
+ preserve_old_decl_size =
+ (DECL_SIZE (olddecl) != NULL_TREE
+ && DECL_SIZE (newdecl) == NULL_TREE
+ && !same_translation_unit_p (olddecl, newdecl));
DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl);
DECL_COMMON (newdecl) = DECL_COMMON (olddecl);
}
*************** merge_decls (tree newdecl, tree olddecl,
*** 1737,1748 ****
--- 1744,1758 ----
{
unsigned olddecl_uid = DECL_UID (olddecl);
tree olddecl_context = DECL_CONTEXT (olddecl);
+ tree olddecl_decl_size = DECL_SIZE (olddecl);
memcpy ((char *) olddecl + sizeof (struct tree_common),
(char *) newdecl + sizeof (struct tree_common),
sizeof (struct tree_decl) - sizeof (struct tree_common));
DECL_UID (olddecl) = olddecl_uid;
DECL_CONTEXT (olddecl) = olddecl_context;
+ if (preserve_old_decl_size)
+ DECL_SIZE (olddecl) = olddecl_decl_size;
}
/* If OLDDECL had its DECL_RTL instantiated, re-invoke make_decl_rtl