From patchwork Sat Apr 2 08:06:29 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Oliva X-Patchwork-Id: 89431 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 94120B6F91 for ; Sat, 2 Apr 2011 19:06:53 +1100 (EST) Received: (qmail 27993 invoked by alias); 2 Apr 2011 08:06:45 -0000 Received: (qmail 27984 invoked by uid 22791); 2 Apr 2011 08:06:43 -0000 X-SWARE-Spam-Status: No, hits=-5.6 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, TW_FN, T_RP_MATCHES_RCVD, T_TVD_MIME_NO_HEADERS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 02 Apr 2011 08:06:38 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p3286a85028543 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Sat, 2 Apr 2011 04:06:36 -0400 Received: from freie.oliva.athome.lsd.ic.unicamp.br (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p3286Xja009643 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Sat, 2 Apr 2011 04:06:35 -0400 Received: from livre.localdomain (livre-to-gw.oliva.athome.lsd.ic.unicamp.br [172.31.160.19]) by freie.oliva.athome.lsd.ic.unicamp.br (8.14.4/8.14.4) with ESMTP id p3286WFJ007715 for ; Sat, 2 Apr 2011 05:06:32 -0300 Received: from livre.localdomain (aoliva@localhost.localdomain [127.0.0.1]) by livre.localdomain (8.14.3/8.14.3/Debian-5+lenny1) with ESMTP id p3286VuP030024; Sat, 2 Apr 2011 05:06:31 -0300 Received: (from aoliva@localhost) by livre.localdomain (8.14.3/8.14.3/Submit) id p3286Tw6030022; Sat, 2 Apr 2011 05:06:29 -0300 From: Alexandre Oliva To: gcc-patches@gcc.gnu.org Subject: [PR 48333] avoid -fcompare-debug errors from builtins in MEM attrs Date: Sat, 02 Apr 2011 05:06:29 -0300 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) MIME-Version: 1.0 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org I caught this with bootstrap-debug-lean, then realized a bug report was open about the same problem. When Jakub introduced MEM attrs for the MEMs that refer to the function to be called, it exposed a rare problem. Say we're compiling a translation unit that, in one function A, calls foo (available as __builtin_foo), and in another function B, calls bar, that GCC internally folded to __builtin_foo, a separate but equivalent FUNCTION_DECL as far as MEM attrs are concerned. While compiling A, we introduce in the MEM attrs hash table an attribute for foo. Then, while compiling B, we find and reuse the same MEM attr. So far, so good. Now, while recompiling for -fcompare-debug, the garbage collector decides to run between the compilations of A and B, and it finds that the MEM attr created for A's RTL is no longer necessary, throwing it away. Then, when it compiles B, it does not find a pre-existing MEM, and introduces one for __builtin_foo. It should be obvious now that the final RTL dumps that -fcompare-debug compares for B will differ in this case, because in one case it will say foo, and in the other, __builtin_foo. This patch avoids this particular instance of the problem by recording the __builtin FUNCTION_DECL in the MEM attrs for calls. This ought to be enough to fix this particular instance of the problem, but I'm a bit concerned that other, more convoluted versions of it might still be lingering around. Changing the tree expressions when creating attributes might be doable, but I find that highly undesirable; another option would be to always dump functions as their builtins; there are probably other options too. This regstrapped on x86_64-linux-gnu. Ok to install? for gcc/ChangeLog from Alexandre Oliva PR debug/48333 * calls.c (emit_call_1): Prefer the __builtin declaration of builtin functions. Index: gcc/calls.c =================================================================== --- gcc/calls.c.orig 2011-03-31 01:40:42.960373301 -0300 +++ gcc/calls.c 2011-03-31 01:46:27.655319378 -0300 @@ -272,7 +272,20 @@ emit_call_1 (rtx funexp, tree fntree ATT funmem = gen_rtx_MEM (FUNCTION_MODE, funexp); if (fndecl && TREE_CODE (fndecl) == FUNCTION_DECL) - set_mem_expr (funmem, fndecl); + { + tree t = fndecl; + /* Although a built-in FUNCTION_DECL and its non-__builtin + counterpart compare equal and get a shared mem_attrs, they + produce different dump output in compare-debug compilations, + if an entry gets garbage collected in one compilation, then + adds a different (but equivalent) entry, while the other + doesn't run the garbage collector at the same spot and then + shares the mem_attr with the equivalent entry. */ + if (DECL_BUILT_IN_CLASS (t) == BUILT_IN_NORMAL + && built_in_decls[DECL_FUNCTION_CODE (t)]) + t = built_in_decls[DECL_FUNCTION_CODE (t)]; + set_mem_expr (funmem, t); + } else if (fntree) set_mem_expr (funmem, build_fold_indirect_ref (CALL_EXPR_FN (fntree)));