* [RFA jit] initialize input_location
@ 2014-01-01 0:00 Tom Tromey
2014-01-01 0:00 ` David Malcolm
0 siblings, 1 reply; 4+ messages in thread
From: Tom Tromey @ 2014-01-01 0:00 UTC (permalink / raw)
To: jit; +Cc: gcc-patches, Tom Tromey
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;
--
1.8.5.3
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [RFA jit] initialize input_location
2014-01-01 0:00 ` David Malcolm
@ 2014-01-01 0:00 ` Tom Tromey
2014-01-01 0:00 ` David Malcolm
0 siblings, 1 reply; 4+ messages in thread
From: Tom Tromey @ 2014-01-01 0:00 UTC (permalink / raw)
To: David Malcolm; +Cc: jit, gcc-patches
>>>>> "Dave" == David Malcolm <dmalcolm-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org> writes:
Dave> Given this declaration in input.c:
Dave> location_t input_location;
Dave> then assigning 0 is a faithful way of resetting it to its initial state.
Dave> That said, "0" feels like a magic number. Would it better to assign
Dave> UNKNOWN_LOCATION to it? which is 0, c.f. input.h:
Dave> #define UNKNOWN_LOCATION ((source_location) 0)
Dave> If so, perhaps the declaration in input.c should gain an initializer to
Dave> the same value? (shouldn't affect the code, since it's 0 either way,
Dave> but perhaps it's more readable?)
Sounds reasonable to me.
How about the appended?
Tom
commit 79ce51eaf41ce7b0e90407245b7cad33ada6887b
Author: Tom Tromey <tromey@redhat.com>
Date: Thu Mar 20 08:51:25 2014 -0600
initialize input_location
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.
diff --git a/gcc/ChangeLog.jit b/gcc/ChangeLog.jit
index ee1df88..5145cf9 100644
--- a/gcc/ChangeLog.jit
+++ b/gcc/ChangeLog.jit
@@ -1,3 +1,8 @@
+2014-03-24 Tom Tromey <tromey@redhat.com>
+
+ * toplev.c (general_init): Initialize input_location.
+ * input.c (input_location): Initialize to UNKNOWN_LOCATION.
+
2014-03-19 Tom Tromey <tromey@redhat.com>
* timevar.h (auto_timevar): New class.
diff --git a/gcc/input.c b/gcc/input.c
index a141a92..90a708c 100644
--- a/gcc/input.c
+++ b/gcc/input.c
@@ -1,5 +1,5 @@
/* Data and functions related to line maps and input files.
- Copyright (C) 2004-2013 Free Software Foundation, Inc.
+ Copyright (C) 2004-2014 Free Software Foundation, Inc.
This file is part of GCC.
@@ -25,7 +25,7 @@ along with GCC; see the file COPYING3. If not see
/* Current position in real source file. */
-location_t input_location;
+location_t input_location = UNKNOWN_LOCATION;
struct line_maps *line_table;
diff --git a/gcc/toplev.c b/gcc/toplev.c
index b257ab2..54a884e 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 = UNKNOWN_LOCATION;
line_table = ggc_alloc_line_maps ();
linemap_init (line_table);
line_table->reallocator = realloc_for_line_map;
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [RFA jit] initialize input_location
2014-01-01 0:00 [RFA jit] initialize input_location Tom Tromey
@ 2014-01-01 0:00 ` David Malcolm
2014-01-01 0:00 ` Tom Tromey
0 siblings, 1 reply; 4+ messages in thread
From: David Malcolm @ 2014-01-01 0:00 UTC (permalink / raw)
To: Tom Tromey; +Cc: jit, gcc-patches
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [RFA jit] initialize input_location
2014-01-01 0:00 ` Tom Tromey
@ 2014-01-01 0:00 ` David Malcolm
0 siblings, 0 replies; 4+ messages in thread
From: David Malcolm @ 2014-01-01 0:00 UTC (permalink / raw)
To: Tom Tromey; +Cc: David Malcolm, jit, gcc-patches
On Mon, 2014-03-24 at 05:29 -0600, Tom Tromey wrote:
>
> >>>>> "Dave" == David Malcolm <dmalcolm-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org> writes:
>
> Dave> Given this declaration in input.c:
> Dave> location_t input_location;
> Dave> then assigning 0 is a faithful way of resetting it to its initial state.
>
> Dave> That said, "0" feels like a magic number. Would it better to assign
> Dave> UNKNOWN_LOCATION to it? which is 0, c.f. input.h:
>
> Dave> #define UNKNOWN_LOCATION ((source_location) 0)
>
> Dave> If so, perhaps the declaration in input.c should gain an initializer to
> Dave> the same value? (shouldn't affect the code, since it's 0 either way,
> Dave> but perhaps it's more readable?)
>
> Sounds reasonable to me.
> How about the appended?
>
> Tom
>
> commit 79ce51eaf41ce7b0e90407245b7cad33ada6887b
> Author: Tom Tromey <tromey@redhat.com>
> Date: Thu Mar 20 08:51:25 2014 -0600
>
> initialize input_location
>
> 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.
>
> diff --git a/gcc/ChangeLog.jit b/gcc/ChangeLog.jit
> index ee1df88..5145cf9 100644
> --- a/gcc/ChangeLog.jit
> +++ b/gcc/ChangeLog.jit
> @@ -1,3 +1,8 @@
> +2014-03-24 Tom Tromey <tromey@redhat.com>
> +
> + * toplev.c (general_init): Initialize input_location.
> + * input.c (input_location): Initialize to UNKNOWN_LOCATION.
> +
> 2014-03-19 Tom Tromey <tromey@redhat.com>
>
> * timevar.h (auto_timevar): New class.
> diff --git a/gcc/input.c b/gcc/input.c
> index a141a92..90a708c 100644
> --- a/gcc/input.c
> +++ b/gcc/input.c
> @@ -1,5 +1,5 @@
> /* Data and functions related to line maps and input files.
> - Copyright (C) 2004-2013 Free Software Foundation, Inc.
> + Copyright (C) 2004-2014 Free Software Foundation, Inc.
>
> This file is part of GCC.
>
> @@ -25,7 +25,7 @@ along with GCC; see the file COPYING3. If not see
>
> /* Current position in real source file. */
>
> -location_t input_location;
> +location_t input_location = UNKNOWN_LOCATION;
>
> struct line_maps *line_table;
>
> diff --git a/gcc/toplev.c b/gcc/toplev.c
> index b257ab2..54a884e 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 = UNKNOWN_LOCATION;
> line_table = ggc_alloc_line_maps ();
> linemap_init (line_table);
> line_table->reallocator = realloc_for_line_map;
Thanks. Feel free to push this to the dmalcolm/jit branch.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-03-24 18:17 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-01 0:00 [RFA jit] initialize input_location Tom Tromey
2014-01-01 0:00 ` David Malcolm
2014-01-01 0:00 ` Tom Tromey
2014-01-01 0:00 ` David Malcolm
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).