Bug 9177 - -fdump-translation-unit: C front end deletes function_decl AST nodes and breaks debugging dumps.
|
Bug#:
9177
|
Product: gcc
|
Version: 3.2
|
|
Host:
|
Target:
|
Build:
|
|
Status: RESOLVED
|
Severity: normal
|
Priority: P3
|
|
Resolution: FIXED
|
Assigned To: unassigned@gcc.gnu.org
|
Reported By: sluncho@mirizma.org
|
|
Component: c
|
Target Milestone: ---
|
|
Summary: -fdump-translation-unit: C front end deletes function_decl AST nodes and breaks debugging dumps.
|
|
Keywords:
|
|
Opened: 2003-01-04 19:46
|
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: analyzed->closed
State-Changed-Why: Patch applied on the 3.3 branch and a variant on mainline.