This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH][C++] Fix dump-file corruption
- From: Richard Guenther <rguenther at suse dot de>
- To: gcc-patches at gcc dot gnu dot org
- Date: Wed, 5 Oct 2005 17:34:41 +0200 (CEST)
- Subject: [PATCH][C++] Fix dump-file corruption
Hi!
Currently cxx_printable_name caches names in a ring in a non-lru
fashion. This causes f.i. the ipa-inline dump to have corrupted
lines like
Considering int& Node<Dom, OrigDom>::affinity() [with Dom = Range<2>,
OrigDom = Interval<2>] with 0 insns to be inlined into
360'270^X^U@outBaseViewData<Dim, Dim2, L>::computeS
ubdomains() const [with int Dim = 2, int Dim2 = 2, L =
UniformGridLayout<200
valgrind happily shows we're reading from freed memory.
The failure situation is simple. Consider printing "%s %s" with
two different decl's and the first decl's name in the ring at the
position where we'll insert the second decl's name and free the firsts
one -> *kaboom* (independent of ring size).
Fixed by moving (swapping) a cached decls name to the position it would
have had if it had been freshly allocated. This ensures that we can
reliably print strings with at least RING_SIZE decl names in them.
Ok for mainline?
Thanks,
Richard.
:ADDPATCH c++:
2005-10-05 Richard Guenther <rguenther@suse.de>
* tree.c (cxx_printable_name): Swap cached entry to head
of the ring before returning it.
Index: cp/tree.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/tree.c,v
retrieving revision 1.443
diff -c -3 -p -r1.443 tree.c
*** cp/tree.c 2 Oct 2005 21:28:49 -0000 1.443
--- cp/tree.c 5 Oct 2005 15:26:52 -0000
*************** cxx_printable_name (tree decl, int v)
*** 886,899 ****
|| DECL_LANG_SPECIFIC (decl) == 0)
return lang_decl_name (decl, v);
/* See if this print name is lying around. */
for (i = 0; i < PRINT_RING_SIZE; i++)
if (decl_ring[i] == decl)
! /* yes, so return it. */
! return print_ring[i];
!
! if (++ring_counter == PRINT_RING_SIZE)
! ring_counter = 0;
if (current_function_decl != NULL_TREE)
{
--- 886,910 ----
|| DECL_LANG_SPECIFIC (decl) == 0)
return lang_decl_name (decl, v);
+ if (++ring_counter == PRINT_RING_SIZE)
+ ring_counter = 0;
+
/* See if this print name is lying around. */
for (i = 0; i < PRINT_RING_SIZE; i++)
if (decl_ring[i] == decl)
! {
! /* yes, so return it, but swap entries to have this one
! freed last. */
! tree decl_tmp;
! char *print_tmp;
! decl_tmp = decl_ring[ring_counter];
! decl_ring[ring_counter] = decl_ring[i];
! decl_ring[i] = decl_tmp;
! print_tmp = print_ring[ring_counter];
! print_ring[ring_counter] = print_ring[i];
! print_ring[i] = print_tmp;
! return print_ring[ring_counter];
! }
if (current_function_decl != NULL_TREE)
{