This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: dump-translation-unit format
- From: Ian Lance Taylor <iant at google dot com>
- To: "Sascha Alexander Jopen" <jopen at gmx dot net>
- Cc: <gcc-help at gcc dot gnu dot org>
- Date: 09 Mar 2007 07:34:02 -0800
- Subject: Re: dump-translation-unit format
- References: <000301c76251$e7081c90$b51855b0$@net>
"Sascha Alexander Jopen" <jopen@gmx.net> writes:
> I'm currently working on the output of gcc/g++ -fdump-translation-unit to do
> source code analysis. I found several references that the internal ast
> should include nodes for for, while and do constructs. But I can't find
> those nodes in the dumped files. Sometimes there are such FOR_STMT nodes
> when I compile large units, but when compiling a small test unit containing
> not much more than a for loop, this loop isn't included in the dump. Instead
> there is a GOTO_EXPR where I would expect the for loop. This holds for other
> loops and conditional expressions as well. All FOR_STMT nodes I encountered
> where not from my custom code, but from templates from system includes.
>
> Are there any optimizations done on the tree before dumping it, and how can
> I prevent this to get an unoptimized tree? Are there other possibilities to
> get those loop nodes? I need them to check whether function calls are done
> in loops or not. Without the bodies of loops I can get information about
> functions called from other functions using the chain links, but not whether
> they are called within loops.
Which version of gcc are you using? In mainline
-fdump-translation-unit just dumps the global declarations. If you
want to see FOR_STMT nodes, you need -fdump-tree-original. But that
is pretty unsatisfactory these days since for_stmt nodes are not
dumped in a useful way. And that only happens for C++; for C FOR_STMT
nodes are never generated.
> Another thing I don't understand is the following. This dumped function node
> contains two body definitions, one undefined and one with a proper node
> chain. Is this a dump error or has it special meaning?
>
> @1639 function_decl name: @2001 mngl: @2002 type: @2003
> scpe: @812 srcp: char_traits.h:322
> chan: @2004 note: member accs: pub
> args: @2005 body: undefined
> link: extern body: @2006
>
> Maybe someone could help me or point me to other resources.
The tree dump code prints out "body: undefined" for an external
function which is not to be compiled by itself. But such a function
can still have a body; this will be the case for a C++ inline
function. This is somewhat confusing.
Ian