From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29489 invoked by alias); 15 Oct 2009 13:30:03 -0000 Received: (qmail 29428 invoked by uid 22791); 15 Oct 2009 13:30:02 -0000 X-SWARE-Spam-Status: No, hits=-3.7 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from cantor2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 15 Oct 2009 13:29:58 +0000 Received: from relay2.suse.de (mail2.suse.de [195.135.221.8]) by mx2.suse.de (Postfix) with ESMTP id 31B6B8B2F9; Thu, 15 Oct 2009 15:29:55 +0200 (CEST) Date: Thu, 15 Oct 2009 13:34:00 -0000 From: Richard Guenther To: gcc-patches@gcc.gnu.org Cc: Diego Novillo Subject: [PATCH][LTO] Fix PR41669, avoid recursing in get_alias_set Message-ID: User-Agent: Alpine 2.00 (LNX 1167 2008-08-23) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2009-10/txt/msg00969.txt.bz2 This avoids the endless recursions we see from time to time between get_alias_set and the gimple langhook implementation. It happens when TYPE_CANONICAL and TYPE_MAIN_VARIANT together with TYPE_POINTER_TO/TYPE_REFERENCE_TO build a cycle. While this is surely a problem with type-merging it's exposed easily by incrementally changing that code for good. This patch papers over the problem - I will keep one bug open to track this. Bootstrap and regtest running - ok if that succeeds? Thanks, Richard. 2009-10-15 Richard Guenther PR lto/41669 * gimple.c (gimple_get_alias_set): Avoid recursing on invalid type topology. * gcc.dg/lto/20091015-1_0.c: New testcase. * gcc.dg/lto/20091015-1_1.c: Likewise. * gcc.dg/lto/20091015-1_2.c: Likewise. * gcc.dg/lto/20091015-1_a.h: Likewise. * gcc.dg/lto/20091015-1_b.h: Likewise. Index: gcc/testsuite/gcc.dg/lto/20091015-1_0.c =================================================================== *** gcc/testsuite/gcc.dg/lto/20091015-1_0.c (revision 0) --- gcc/testsuite/gcc.dg/lto/20091015-1_0.c (revision 0) *************** *** 0 **** --- 1,5 ---- + /* { dg-lto-do link } */ + /* { dg-lto-options {{-fPIC -shared -O2 -flto} {-fPIC -shared -O2 -fwhopr}} } */ + + #include "20091015-1_b.h" + void diagnostic_initialize (FILE **stream) { *stream = stderr; } Index: gcc/testsuite/gcc.dg/lto/20091015-1_1.c =================================================================== *** gcc/testsuite/gcc.dg/lto/20091015-1_1.c (revision 0) --- gcc/testsuite/gcc.dg/lto/20091015-1_1.c (revision 0) *************** *** 0 **** --- 1,4 ---- + #include "20091015-1_a.h" + #include "20091015-1_b.h" + void ggc_print_common_statistics (FILE *stream) { + } Index: gcc/testsuite/gcc.dg/lto/20091015-1_2.c =================================================================== *** gcc/testsuite/gcc.dg/lto/20091015-1_2.c (revision 0) --- gcc/testsuite/gcc.dg/lto/20091015-1_2.c (revision 0) *************** *** 0 **** --- 1,5 ---- + #include "20091015-1_a.h" + #include "20091015-1_b.h" + void debug_optab_libfuncs (void) { + foo (stderr, 4 ); + } Index: gcc/testsuite/gcc.dg/lto/20091015-1_a.h =================================================================== *** gcc/testsuite/gcc.dg/lto/20091015-1_a.h (revision 0) --- gcc/testsuite/gcc.dg/lto/20091015-1_a.h (revision 0) *************** *** 0 **** --- 1,2 ---- + struct _IO_FILE { int _flags; + }; Index: gcc/testsuite/gcc.dg/lto/20091015-1_b.h =================================================================== *** gcc/testsuite/gcc.dg/lto/20091015-1_b.h (revision 0) --- gcc/testsuite/gcc.dg/lto/20091015-1_b.h (revision 0) *************** *** 0 **** --- 1,2 ---- + typedef struct _IO_FILE FILE; + extern struct _IO_FILE *stderr; Index: gcc/gimple.c =================================================================== --- gcc/gimple.c.orig 2009-10-15 15:24:59.000000000 +0200 +++ gcc/gimple.c 2009-10-15 15:19:11.000000000 +0200 @@ -4121,6 +4121,7 @@ gimple_signed_type (tree type) alias_set_type gimple_get_alias_set (tree t) { + static bool recursing_p; tree u; /* Permit type-punning when accessing a union, provided the access @@ -4162,6 +4163,12 @@ gimple_get_alias_set (tree t) { tree t1; + /* ??? We can end up creating cycles with TYPE_MAIN_VARIANT + and TYPE_CANONICAL. Avoid recursing endlessly between + this langhook and get_alias_set. */ + if (recursing_p) + return -1; + /* Unfortunately, there is no canonical form of a pointer type. In particular, if we have `typedef int I', then `int *', and `I *' are different types. So, we have to pick a canonical @@ -4186,7 +4193,13 @@ gimple_get_alias_set (tree t) C++ committee. */ t1 = build_type_no_quals (t); if (t1 != t) - return get_alias_set (t1); + { + alias_set_type set; + recursing_p = true; + set = get_alias_set (t1); + recursing_p = false; + return set; + } } return -1;