debug: Handle x_flag_var_tracking_* in finish_options [PR102585]

Message ID aa789d71-fddb-9111-8734-0c3faba529e0@suse.cz
State New
Headers
Series debug: Handle x_flag_var_tracking_* in finish_options [PR102585] |

Commit Message

Martin Liška Oct. 4, 2021, 10:31 a.m. UTC
  Hello.

The patch sets -1 for x_flag_var_tracking and x_flag_var_tracking_assignments similarly
to toplev.c.

Patch can bootstrap on x86_64-linux-gnu and survives regression tests.

Ready to be installed?
Thanks,
Martin

	PR debug/102585

gcc/ChangeLog:

	* opts.c (finish_options): Similarly to toplev.c
	  (process_options), set value -1.

gcc/testsuite/ChangeLog:

	* gcc.dg/pr102585.c: New test.
---
  gcc/opts.c                      | 3 +++
  gcc/testsuite/gcc.dg/pr102585.c | 6 ++++++
  2 files changed, 9 insertions(+)
  create mode 100644 gcc/testsuite/gcc.dg/pr102585.c
  

Comments

Richard Biener Oct. 4, 2021, 11:41 a.m. UTC | #1
On Mon, Oct 4, 2021 at 12:31 PM Martin Liška <mliska@suse.cz> wrote:
>
> Hello.
>
> The patch sets -1 for x_flag_var_tracking and x_flag_var_tracking_assignments similarly
> to toplev.c.
>
> Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
>
> Ready to be installed?
> Thanks,
> Martin
>
>         PR debug/102585
>
> gcc/ChangeLog:
>
>         * opts.c (finish_options): Similarly to toplev.c
>           (process_options), set value -1.
>
> gcc/testsuite/ChangeLog:
>
>         * gcc.dg/pr102585.c: New test.
> ---
>   gcc/opts.c                      | 3 +++
>   gcc/testsuite/gcc.dg/pr102585.c | 6 ++++++
>   2 files changed, 9 insertions(+)
>   create mode 100644 gcc/testsuite/gcc.dg/pr102585.c
>
> diff --git a/gcc/opts.c b/gcc/opts.c
> index 6503980cd33..f2f058b3ece 100644
> --- a/gcc/opts.c
> +++ b/gcc/opts.c
> @@ -1343,6 +1343,9 @@ finish_options (struct gcc_options *opts, struct gcc_options *opts_set,
>       opts->x_flag_complex_method = 1;
>     else if (opts_set->x_flag_cx_fortran_rules)
>       opts->x_flag_complex_method = opts->x_flag_default_complex_method;
> +
> +  if (opts->x_flag_var_tracking_assignments && !opts->x_flag_var_tracking)
> +    opts->x_flag_var_tracking = opts->x_flag_var_tracking_assignments = -1;

I can see how this affects later tests in process_options like

  if (flag_var_tracking_uninit == AUTODETECT_VALUE)
    flag_var_tracking_uninit = flag_var_tracking;

would now become -1 instead of zero?

So iff then probably this whole block would need to move but the option
handling code is a sophisticated mess between FE, target and middle-end ...

diff --git a/gcc/toplev.c b/gcc/toplev.c
index ec9f998a49b..fec72b1365a 100644
--- a/gcc/toplev.c
+++ b/gcc/toplev.c
@@ -2147,8 +2147,6 @@ standard_type_bitsize (int bitsize)
 static void
 do_compile ()
 {
-  process_options ();
-
   /* Don't do any more if an error has already occurred.  */
   if (!seen_error ())
     {
@@ -2368,6 +2366,8 @@ toplev::main (int argc, char **argv)
   /* Exit early if we can (e.g. -help).  */
   if (!exit_after_options)
     {
+      process_options ();
+
       if (m_use_TV_TOTAL)
        start_timevars ();
       do_compile ();

would at least make the flow a bit more obvious ;)  IIRC process_options
was/is supposed to be the place to emit diagnostics about options but
clearly it's doing even more.  I guess outlining the call to
lang_hooks.post_options
would be another piece to make the flow clearer, likewise setting of
optimization_default_node ...

Richard.

>   }
>
>   #define LEFT_COLUMN   27
> diff --git a/gcc/testsuite/gcc.dg/pr102585.c b/gcc/testsuite/gcc.dg/pr102585.c
> new file mode 100644
> index 00000000000..efd066b4a4e
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/pr102585.c
> @@ -0,0 +1,6 @@
> +/* PR debug/102585 */
> +/* { dg-do compile } */
> +/* { dg-options "-fvar-tracking-assignments -fno-var-tracking" } */
> +
> +#pragma GCC optimize 0
> +void d_demangle_callback_Og() { int c = 0; }
> --
> 2.33.0
>
  
Jakub Jelinek Oct. 4, 2021, 11:45 a.m. UTC | #2
On Mon, Oct 04, 2021 at 01:41:36PM +0200, Richard Biener via Gcc-patches wrote:
> > The patch sets -1 for x_flag_var_tracking and x_flag_var_tracking_assignments similarly
> > to toplev.c.
> >
> > Patch can bootstrap on x86_64-linux-gnu and survives regression tests.

Shouldn't all those flag_* == AUTODETECT_VALUE be converted to
!global_options_set.x_flag_* or at least
!global_options_set.x_flag_* && flag_* == AUTODETECT_VALUE ?

	Jakub
  
Martin Liška Oct. 4, 2021, 12:16 p.m. UTC | #3
On 10/4/21 13:45, Jakub Jelinek wrote:
> On Mon, Oct 04, 2021 at 01:41:36PM +0200, Richard Biener via Gcc-patches wrote:
>>> The patch sets -1 for x_flag_var_tracking and x_flag_var_tracking_assignments similarly
>>> to toplev.c.
>>>
>>> Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
> 
> Shouldn't all those flag_* == AUTODETECT_VALUE be converted to
> !global_options_set.x_flag_* or at least
> !global_options_set.x_flag_* && flag_* == AUTODETECT_VALUE ?

Reading the code one more time, yes, I think so. It's pretty ugly code right now,
let me investigate what can we do with that..

Martin
  

Patch

diff --git a/gcc/opts.c b/gcc/opts.c
index 6503980cd33..f2f058b3ece 100644
--- a/gcc/opts.c
+++ b/gcc/opts.c
@@ -1343,6 +1343,9 @@  finish_options (struct gcc_options *opts, struct gcc_options *opts_set,
      opts->x_flag_complex_method = 1;
    else if (opts_set->x_flag_cx_fortran_rules)
      opts->x_flag_complex_method = opts->x_flag_default_complex_method;
+
+  if (opts->x_flag_var_tracking_assignments && !opts->x_flag_var_tracking)
+    opts->x_flag_var_tracking = opts->x_flag_var_tracking_assignments = -1;
  }
  
  #define LEFT_COLUMN	27
diff --git a/gcc/testsuite/gcc.dg/pr102585.c b/gcc/testsuite/gcc.dg/pr102585.c
new file mode 100644
index 00000000000..efd066b4a4e
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr102585.c
@@ -0,0 +1,6 @@ 
+/* PR debug/102585 */
+/* { dg-do compile } */
+/* { dg-options "-fvar-tracking-assignments -fno-var-tracking" } */
+
+#pragma GCC optimize 0
+void d_demangle_callback_Og() { int c = 0; }