This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Clean up pretty printers [10/n]
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Dodji Seketeli <dseketel at redhat dot com>, Gabriel Dos Reis <gdr at axiomatics dot org>, Jason Merrill <jason at redhat dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Wed, 12 Feb 2014 17:29:40 +0100
- Subject: Re: Clean up pretty printers [10/n]
- Authentication-results: sourceware.org; auth=none
- References: <87ioyyqatx dot fsf at euclid dot axiomatics dot org>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Thu, Aug 22, 2013 at 05:27:54AM -0500, Gabriel Dos Reis wrote:
> * error.c (init_error): Remove calls to pp_construct and
> pp_cxx_pretty_printer_init. Initialize cxx_pp with placement-new.
> * cxx-pretty-print.h (cxx_pretty_printer::cxx_pretty_printer): Declare.
> (cxx_pretty_printer_init): Remove.
> * cxx-pretty-print.c (cxx_pretty_printer::cxx_pretty_printer):
> Rename from cxx_pretty_printer_init. Adjust.
> * cp-objcp-common.c (cxx_initialize_diagnostics): Simplify
> initialization of C++ diagnostics pretty printer.
> --- cp/error.c (revision 201904)
> +++ cp/error.c (working copy)
> @@ -33,6 +33,8 @@
> #include "pointer-set.h"
> #include "c-family/c-objc.h"
>
> +#include <new> // For placement-new.
> +
> #define pp_separate_with_comma(PP) pp_cxx_separate_with (PP, ',')
> #define pp_separate_with_semicolon(PP) pp_cxx_separate_with (PP, ';')
>
> @@ -109,8 +111,7 @@
> diagnostic_finalizer (global_dc) = cp_diagnostic_finalizer;
> diagnostic_format_decoder (global_dc) = cp_printer;
>
> - pp_construct (cxx_pp, NULL, 0);
> - pp_cxx_pretty_printer_init (cxx_pp);
> + new (cxx_pp) cxx_pretty_printer ();
Unfortunately this always leaks memory,
static cxx_pretty_printer scratch_pretty_printer;
is constructed first during static initialization, where it e.g. allocates
through XNEW the buffer, and then when init_error is called, it ignores
the old content of scratch_pretty_printer and constructs the same objects
again. Why is the new (cxx_pp) cxx_pretty_printer (); line needed at all?
Isn't it already constructed with the right ctor?
Or, shouldn't it at least first try to call destructor?
I think there are more spots with placement new, perhaps all have the same
issue?
Jakub