[Bug c/26613] New: Corner case causes garbage to be output by -aux-info switch.

2006-03-08 Thread markfhaigh at sbcglobal dot net
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



[Bug c/26613] Corner case causes garbage to be output by -aux-info switch.

2006-03-08 Thread markfhaigh at sbcglobal dot net


--- Comment #1 from markfhaigh at sbcglobal dot net  2006-03-09 07:02 
---
Created an attachment (id=11001)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=11001&action=view)
Fix for 3.3.x branch (against 2006-03-03 CVS)


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26613



[Bug c/26613] Corner case causes garbage to be output by -aux-info switch.

2006-03-08 Thread markfhaigh at sbcglobal dot net


--- Comment #2 from markfhaigh at sbcglobal dot net  2006-03-09 07:03 
---
Created an attachment (id=11002)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=11002&action=view)
Fix for 3.4.x branch (against 2006-03-03 CVS)


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26613



[Bug c/26613] Corner case causes garbage to be output by -aux-info switch.

2006-03-08 Thread markfhaigh at sbcglobal dot net


--- Comment #3 from markfhaigh at sbcglobal dot net  2006-03-09 07:04 
---
Created an attachment (id=11003)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=11003&action=view)
Fix for 4.0.x branch (against 2006-03-03 CVS)


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26613



[Bug c/26613] Corner case causes garbage to be output by -aux-info switch.

2006-03-08 Thread markfhaigh at sbcglobal dot net


--- Comment #4 from markfhaigh at sbcglobal dot net  2006-03-09 07:05 
---
Created an attachment (id=11004)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=11004&action=view)
Fix for 4.1.x branch (against 2006-03-03 CVS)


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26613



[Bug c/26613] Corner case causes garbage to be output by -aux-info switch.

2006-03-08 Thread markfhaigh at sbcglobal dot net


--- Comment #5 from markfhaigh at sbcglobal dot net  2006-03-09 07:06 
---
Created an attachment (id=11005)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=11005&action=view)
Fix for trunk (against 2006-03-03 CVS)


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26613