This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [RFA jit] initialize input_location
- From: David Malcolm <dmalcolm at redhat dot com>
- To: Tom Tromey <tromey at redhat dot com>
- Cc: jit at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Date: Fri, 21 Mar 2014 18:18:38 -0400
- Subject: Re: [RFA jit] initialize input_location
- Authentication-results: sourceware.org; auth=none
- References: <1395327187-14524-1-git-send-email-tromey at redhat dot com>
On Thu, 2014-03-20 at 08:53 -0600, Tom Tromey wrote:
> This patch initializes input_location at the same spot where the line
> table is initialized. Without this, it's possible to crash when
> emitting a diagnostic in a reinvocation of the compiler, because
> input_location refers to a location that is no longer valid.
> ---
> gcc/ChangeLog.jit | 4 ++++
> gcc/toplev.c | 1 +
> 2 files changed, 5 insertions(+)
>
> diff --git a/gcc/ChangeLog.jit b/gcc/ChangeLog.jit
> index ee1df88..a9b0817 100644
> --- a/gcc/ChangeLog.jit
> +++ b/gcc/ChangeLog.jit
> @@ -1,5 +1,9 @@
> 2014-03-19 Tom Tromey <tromey@redhat.com>
>
> + * toplev.c (general_init): Initialize input_location.
> +
> +2014-03-19 Tom Tromey <tromey@redhat.com>
> +
> * timevar.h (auto_timevar): New class.
>
> 2014-03-19 Tom Tromey <tromey@redhat.com>
> diff --git a/gcc/toplev.c b/gcc/toplev.c
> index b257ab2..1febc2e 100644
> --- a/gcc/toplev.c
> +++ b/gcc/toplev.c
> @@ -1161,6 +1161,7 @@ general_init (const char *argv0)
> table. */
> init_ggc ();
> init_stringpool ();
> + input_location = 0;
> line_table = ggc_alloc_line_maps ();
> linemap_init (line_table);
> line_table->reallocator = realloc_for_line_map;
Given this declaration in input.c:
location_t input_location;
then assigning 0 is a faithful way of resetting it to its initial state.
That said, "0" feels like a magic number. Would it better to assign
UNKNOWN_LOCATION to it? which is 0, c.f. input.h:
#define UNKNOWN_LOCATION ((source_location) 0)
If so, perhaps the declaration in input.c should gain an initializer to
the same value? (shouldn't affect the code, since it's 0 either way,
but perhaps it's more readable?)
Dave