public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* c/9177: The C front end deletes function_decl AST nodes and breaks debugging dumps.
@ 2003-01-05  3:47 sluncho
  0 siblings, 0 replies; only message in thread
From: sluncho @ 2003-01-05  3:47 UTC (permalink / raw)
  To: gcc-gnats


>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:


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2003-01-05  3:47 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-01-05  3:47 c/9177: The C front end deletes function_decl AST nodes and breaks debugging dumps sluncho

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).