The gen_type() function in gcc/c-aux-info.c contains a logic bug that causes
garbage to be output to the file specified by the -aux-info switch.
The crux of the problem is that gen_type() uses a global variable (data_type)
to build parts of the string to be output by -aux-info. However, there are two
cases where gen_type() indirectly recurses via gen_decl().
Of course, this recursing will overwrite the global variable, and upon return
from the recursion, the "original" value has been lost forever. This causes
corrupted output into the aux-info file.
This behavior occurs on all targets, and all known versions of gcc since the
-aux-info feature was added. I have confirmed that it occurs on the latest CVS
sources for 3.3, 3.4, 4.0, 4.1 branches as well as the trunk (currently 4.2).
The problem was triggered by a particularly perverse code generator that (in
one of its own corner cases), generates a function taking an argument that is a
pointer to an anonymous structure declared inside a parameter list. Strange,
but legal.
You can use the following to reproduce:
/* --- File foo.c --- */
void foo (struct { int a; int b; } * p)
{
}
gcc -Wall -O2 -o foo.o -aux-info foo.X -c foo.c
This causes the following output into foo.X:
/* compiled from: . */
/* foo.c:3:NF */ extern void foo (struct { intint b; } *p); /* (p) struct {
intint b; } *p; */
As you can see, the type of the argument to foo is corrupted.
The correct output is:
/* compiled from: . */
/* foo.c:3:NF */ extern void foo (struct { int a; int b; } *p); /* (p) struct {
int a; int b; } *p; */
Fortunately, the fix is small, isolated, and low-risk. You simply save a copy
of the contents of the global variable before any recursion. Since it's
actually affecting me, I request that you apply the fix to 3.3, 3.4, 4.0, 4.1,
and the trunk as soon as is feasible.
I will be posting the patches (to the latest CVS) for 3.3, 3.4, 4.0, 4.1, and
trunk to gcc-patches as soon as I'm done entering this.
Thanks!
Mark F. Haigh
[EMAIL PROTECTED]
--
Summary: Corner case causes garbage to be output by -aux-info
switch.
Product: gcc
Version: 4.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: markfhaigh at sbcglobal dot net
GCC build triplet: All
GCC host triplet: All
GCC target triplet: All
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26613