From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15573 invoked by alias); 5 Jan 2003 03:47:04 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 15526 invoked by uid 71); 5 Jan 2003 03:46:48 -0000 Resent-Date: 5 Jan 2003 03:46:48 -0000 Resent-Message-ID: <20030105034648.15525.qmail@sources.redhat.com> Resent-From: gcc-gnats@gcc.gnu.org (GNATS Filer) Resent-Cc: gcc-prs@gcc.gnu.org, gcc-bugs@gcc.gnu.org Resent-Reply-To: gcc-gnats@gcc.gnu.org, sluncho@mirizma.org Received: (qmail 14069 invoked by uid 61); 5 Jan 2003 03:41:57 -0000 Message-Id: <20030105034157.14068.qmail@sources.redhat.com> Date: Sun, 05 Jan 2003 03:47:00 -0000 From: sluncho@mirizma.org Reply-To: sluncho@mirizma.org To: gcc-gnats@gcc.gnu.org X-Send-Pr-Version: gnatsweb-2.9.3 (1.1.1.1.2.31) Subject: c/9177: The C front end deletes function_decl AST nodes and breaks debugging dumps. X-SW-Source: 2003-01/txt/msg00303.txt.bz2 List-Id: >Number: 9177 >Category: c >Synopsis: The C front end deletes function_decl AST nodes and breaks debugging dumps. >Confidential: no >Severity: non-critical >Priority: low >Responsible: unassigned >State: open >Class: sw-bug >Submitter-Id: net >Arrival-Date: Sat Jan 04 19:46:27 PST 2003 >Closed-Date: >Last-Modified: >Originator: sluncho@mirizma.org >Release: gcc-3.2 >Organization: >Environment: linux-i686 >Description: There is a bug that affects the gcc translation unit dump functionality. When dumping the intermediate representation with the -fdump-translation-unit option, gcc generates a .tu file that contains FUNCTION_DECL nodes without a body. .tu file generated by gcc @1 function_decl name: @2 type: @3 srcp: a.c:9 chan: @4 extern The function body is not included in the dump. Invoking g++ with the -fdump-translation-unit option generates a .tu file that contains the function body. .tu file generated by g++ @3 function_decl name: @4 type: @5 srcp: a.c:9 chan: @6 C extern body: @7 The body field points to a compound_stmt node, which contains the function body. The C++ frontend behaves correctly. There is a bug in the C frontend which makes it generate incomplete dumps. The problem is in c-decl.c. After the RTL is generated, the function body (pointed to by DECL_SAVED_TREE) is discarded. /* Generate the RTL for this function. */ expand_stmt (DECL_SAVED_TREE (fndecl)); /* Keep the function body if it's needed for inlining or dumping */ if (uninlinable) { /* Allow the body of the function to be garbage collected. */ DECL_SAVED_TREE (fndecl) = NULL_TREE; } The code is only executed by the C frontend. The C++ frontend contains a similar section of code in cp/semantics.c, but it checks whether the dump mode is enabled and keeps the function body in that case. /* If possible, obliterate the body of the function so that it can be garbage collected. */ if (dump_enabled_p (TDI_all)) /* Keep the body; we're going to dump it. */ ; else if (DECL_INLINE (fn) && flag_inline_trees) /* We might need the body of this function so that we can expand it inline somewhere else. */ ; else /* We don't need the body; blow it away. */ DECL_SAVED_TREE (fn) = NULL_TREE; Patching c-decl.c to check for the dump mode is trivial. A patched gcc generates the correct dump: .tu file generated by patched gcc @1 function_decl name: @2 type: @3 srcp: a.c:9 chan: @4 extern body: @5 >How-To-Repeat: gcc -fdump-translation-unit a.c a.c can be any C source file. This will generate a.c.tu file. All function_decl nodes in a.c.tu will have no body attribute. >Fix: diff -ru gcc-3.2.orig/gcc/c-decl.c gcc-3.2/gcc/c-decl.c --- gcc-3.2.orig/gcc/c-decl.c 2002-07-26 18:23:03.000000000 -0500 +++ gcc-3.2/gcc/c-decl.c 2002-11-10 02:04:50.000000000 -0600 @@ -7091,7 +7091,9 @@ /* Generate the RTL for this function. */ expand_stmt (DECL_SAVED_TREE (fndecl)); - if (uninlinable) + + /* Keep the function body if it's needed for inlining or dumping */ + if (uninlinable && !dump_enabled_p (TDI_all)) { /* Allow the body of the function to be garbage collected. */ DECL_SAVED_TREE (fndecl) = NULL_TREE; >Release-Note: >Audit-Trail: >Unformatted: