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 Release: gcc-3.2 Environment: linux-i686 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;
State-Changed-From-To: open->analyzed State-Changed-Why: Patch submitted by reporter: http://gcc.gnu.org/ml/gcc-patches/2003-02/msg01315.html
From: gerald@gcc.gnu.org To: gcc-gnats@gcc.gnu.org Cc: Subject: c/9177 Date: 18 Apr 2003 19:39:33 -0000 CVSROOT: /cvs/gcc Module name: gcc Changes by: gerald@gcc.gnu.org 2003-04-18 19:39:33 Modified files: gcc : ChangeLog c-decl.c Log message: PR c/9177 * c-decl.c (c_expand_body): Don't garbage collect the function body if we are going to dump it later. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=1.17510&r2=1.17511 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-decl.c.diff?cvsroot=gcc&r1=1.381&r2=1.382
State-Changed-From-To: analyzed->closed State-Changed-Why: Patch applied on the 3.3 branch and a variant on mainline.
Subject: Bug 9177 CVSROOT: /cvs/gcc Module name: gcc Changes by: mkoch@gcc.gnu.org 2004-07-17 08:43:43 Modified files: libjava : ChangeLog libjava/java/nio: ByteOrder.java libjava/java/nio/charset: CharsetDecoder.java Log message: 2004-07-17 Michael Koch <konqueror@gmx.de> * java/nio/ByteOrder.java (static): Removed. Not needed. Thanks to Patrick Reali for noticing. * java/nio/charset/CharsetDecoder.java (decode): Fix for classpath bug #9177: Reset state before flipping. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/ChangeLog.diff?cvsroot=gcc&r1=1.2944&r2=1.2945 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/java/nio/ByteOrder.java.diff?cvsroot=gcc&r1=1.4&r2=1.5 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/java/nio/charset/CharsetDecoder.java.diff?cvsroot=gcc&r1=1.1&r2=1.2