public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] options: Fix variable tracking option processing.
@ 2021-10-11 11:01 Martin Liška
  2021-10-11 13:05 ` Richard Biener
  0 siblings, 1 reply; 20+ messages in thread
From: Martin Liška @ 2021-10-11 11:01 UTC (permalink / raw)
  To: gcc-patches

After the recent change in Optimize attribute handling, we need
finish_option function properly auto-detecting variable tracking options.

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

Ready to be installed?
Thanks,
Martin

	PR debug/102585

gcc/ChangeLog:

	* common.opt: Do not init flag_var_tracking* options.
	* opts.c (finish_options): Handle flag_var_tracking* options.
	* toplev.c (process_options): Move to opts.c.

gcc/testsuite/ChangeLog:

	* gcc.dg/pr102585.c: New test.
---
  gcc/common.opt                  | 14 +++++---------
  gcc/opts.c                      | 28 ++++++++++++++++++++++++++++
  gcc/testsuite/gcc.dg/pr102585.c |  6 ++++++
  gcc/toplev.c                    | 33 +++------------------------------
  4 files changed, 42 insertions(+), 39 deletions(-)
  create mode 100644 gcc/testsuite/gcc.dg/pr102585.c

diff --git a/gcc/common.opt b/gcc/common.opt
index 52693e226d2..ec020f4e642 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -3003,19 +3003,16 @@ Common Undocumented Var(flag_use_linker_plugin)
  
  ; Positive if we should track variables, negative if we should run
  ; the var-tracking pass only to discard debug annotations, zero if
-; we're not to run it.  When flag_var_tracking == 2 (AUTODETECT_VALUE) it
-; will be set according to optimize, debug_info_level and debug_hooks
-; in process_options ().
+; we're not to run it.
  fvar-tracking
-Common Var(flag_var_tracking) Init(2) PerFunction
+Common Var(flag_var_tracking) PerFunction
  Perform variable tracking.
  
  ; Positive if we should track variables at assignments, negative if
  ; we should run the var-tracking pass only to discard debug
-; annotations.  When flag_var_tracking_assignments ==
-; AUTODETECT_VALUE it will be set according to flag_var_tracking.
+; annotations.
  fvar-tracking-assignments
-Common Var(flag_var_tracking_assignments) Init(2) PerFunction
+Common Var(flag_var_tracking_assignments) PerFunction
  Perform variable tracking by annotating assignments.
  
  ; Nonzero if we should toggle flag_var_tracking_assignments after
@@ -3026,8 +3023,7 @@ Toggle -fvar-tracking-assignments.
  
  ; Positive if we should track uninitialized variables, negative if
  ; we should run the var-tracking pass only to discard debug
-; annotations.  When flag_var_tracking_uninit == AUTODETECT_VALUE it
-; will be set according to flag_var_tracking.
+; annotations.
  fvar-tracking-uninit
  Common Var(flag_var_tracking_uninit) PerFunction
  Perform variable tracking and also tag variables that are uninitialized.
diff --git a/gcc/opts.c b/gcc/opts.c
index 2116c2991dd..eeb6b1dcc7c 100644
--- a/gcc/opts.c
+++ b/gcc/opts.c
@@ -1353,6 +1353,34 @@ finish_options (struct gcc_options *opts, struct gcc_options *opts_set,
      SET_OPTION_IF_UNSET (opts, opts_set, flag_vect_cost_model,
  			 VECT_COST_MODEL_CHEAP);
  
+  /* If the user specifically requested variable tracking with tagging
+     uninitialized variables, we need to turn on variable tracking.
+     (We already determined above that variable tracking is feasible.)  */
+  if (opts->x_flag_var_tracking_uninit == 1)
+    opts->x_flag_var_tracking = 1;
+
+  if (!opts_set->x_flag_var_tracking)
+    opts->x_flag_var_tracking = optimize >= 1;
+
+  if (!opts_set->x_flag_var_tracking_uninit)
+    opts->x_flag_var_tracking_uninit = opts->x_flag_var_tracking;
+
+  if (!opts_set->x_flag_var_tracking_assignments)
+    opts->x_flag_var_tracking_assignments
+      = (opts->x_flag_var_tracking
+	 && !(opts->x_flag_selective_scheduling
+	      || opts->x_flag_selective_scheduling2));
+
+  if (opts->x_flag_var_tracking_assignments_toggle)
+    opts->x_flag_var_tracking_assignments = !opts->x_flag_var_tracking_assignments;
+
+  if (opts->x_flag_var_tracking_assignments && !opts->x_flag_var_tracking)
+    opts->x_flag_var_tracking = opts->x_flag_var_tracking_assignments = -1;
+
+  if (opts->x_flag_var_tracking_assignments
+      && (opts->x_flag_selective_scheduling || opts->x_flag_selective_scheduling2))
+    warning_at (loc, 0,
+		"var-tracking-assignments changes selective scheduling");
  }
  
  #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; }
diff --git a/gcc/toplev.c b/gcc/toplev.c
index 81748b1152a..2f13d740b98 100644
--- a/gcc/toplev.c
+++ b/gcc/toplev.c
@@ -1490,8 +1490,8 @@ process_options (bool no_backend)
        || !dwarf_debuginfo_p ()
        || debug_hooks->var_location == do_nothing_debug_hooks.var_location)
      {
-      if (flag_var_tracking == 1
-	  || flag_var_tracking_uninit == 1)
+      if ((OPTION_SET_P (flag_var_tracking) && flag_var_tracking == 1)
+	  || (OPTION_SET_P (flag_var_tracking_uninit) && flag_var_tracking_uninit == 1))
          {
  	  if (debug_info_level < DINFO_LEVEL_NORMAL)
  	    warning_at (UNKNOWN_LOCATION, 0,
@@ -1504,6 +1504,7 @@ process_options (bool no_backend)
  	}
        flag_var_tracking = 0;
        flag_var_tracking_uninit = 0;
+      flag_var_tracking_assignments = 0;
      }
  
    /* The debug hooks are used to implement -fdump-go-spec because it
@@ -1512,34 +1513,6 @@ process_options (bool no_backend)
    if (flag_dump_go_spec != NULL)
      debug_hooks = dump_go_spec_init (flag_dump_go_spec, debug_hooks);
  
-  /* If the user specifically requested variable tracking with tagging
-     uninitialized variables, we need to turn on variable tracking.
-     (We already determined above that variable tracking is feasible.)  */
-  if (flag_var_tracking_uninit == 1)
-    flag_var_tracking = 1;
-
-  if (flag_var_tracking == AUTODETECT_VALUE)
-    flag_var_tracking = optimize >= 1;
-
-  if (flag_var_tracking_uninit == AUTODETECT_VALUE)
-    flag_var_tracking_uninit = flag_var_tracking;
-
-  if (flag_var_tracking_assignments == AUTODETECT_VALUE)
-    flag_var_tracking_assignments
-      = (flag_var_tracking
-	 && !(flag_selective_scheduling || flag_selective_scheduling2));
-
-  if (flag_var_tracking_assignments_toggle)
-    flag_var_tracking_assignments = !flag_var_tracking_assignments;
-
-  if (flag_var_tracking_assignments && !flag_var_tracking)
-    flag_var_tracking = flag_var_tracking_assignments = -1;
-
-  if (flag_var_tracking_assignments
-      && (flag_selective_scheduling || flag_selective_scheduling2))
-    warning_at (UNKNOWN_LOCATION, 0,
-		"var-tracking-assignments changes selective scheduling");
-
    if (debug_nonbind_markers_p == AUTODETECT_VALUE)
      debug_nonbind_markers_p
        = (optimize
-- 
2.33.0


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH] options: Fix variable tracking option processing.
  2021-10-11 11:01 [PATCH] options: Fix variable tracking option processing Martin Liška
@ 2021-10-11 13:05 ` Richard Biener
  2021-10-11 13:21   ` Martin Liška
  0 siblings, 1 reply; 20+ messages in thread
From: Richard Biener @ 2021-10-11 13:05 UTC (permalink / raw)
  To: Martin Liška; +Cc: GCC Patches

On Mon, Oct 11, 2021 at 1:02 PM Martin Liška <mliska@suse.cz> wrote:
>
> After the recent change in Optimize attribute handling, we need
> finish_option function properly auto-detecting variable tracking options.
>
> Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
>
> Ready to be installed?
> Thanks,
> Martin
>
>         PR debug/102585
>
> gcc/ChangeLog:
>
>         * common.opt: Do not init flag_var_tracking* options.
>         * opts.c (finish_options): Handle flag_var_tracking* options.
>         * toplev.c (process_options): Move to opts.c.
>
> gcc/testsuite/ChangeLog:
>
>         * gcc.dg/pr102585.c: New test.
> ---
>   gcc/common.opt                  | 14 +++++---------
>   gcc/opts.c                      | 28 ++++++++++++++++++++++++++++
>   gcc/testsuite/gcc.dg/pr102585.c |  6 ++++++
>   gcc/toplev.c                    | 33 +++------------------------------
>   4 files changed, 42 insertions(+), 39 deletions(-)
>   create mode 100644 gcc/testsuite/gcc.dg/pr102585.c
>
> diff --git a/gcc/common.opt b/gcc/common.opt
> index 52693e226d2..ec020f4e642 100644
> --- a/gcc/common.opt
> +++ b/gcc/common.opt
> @@ -3003,19 +3003,16 @@ Common Undocumented Var(flag_use_linker_plugin)
>
>   ; Positive if we should track variables, negative if we should run
>   ; the var-tracking pass only to discard debug annotations, zero if
> -; we're not to run it.  When flag_var_tracking == 2 (AUTODETECT_VALUE) it
> -; will be set according to optimize, debug_info_level and debug_hooks
> -; in process_options ().
> +; we're not to run it.
>   fvar-tracking
> -Common Var(flag_var_tracking) Init(2) PerFunction
> +Common Var(flag_var_tracking) PerFunction
>   Perform variable tracking.
>
>   ; Positive if we should track variables at assignments, negative if
>   ; we should run the var-tracking pass only to discard debug
> -; annotations.  When flag_var_tracking_assignments ==
> -; AUTODETECT_VALUE it will be set according to flag_var_tracking.
> +; annotations.
>   fvar-tracking-assignments
> -Common Var(flag_var_tracking_assignments) Init(2) PerFunction
> +Common Var(flag_var_tracking_assignments) PerFunction
>   Perform variable tracking by annotating assignments.
>
>   ; Nonzero if we should toggle flag_var_tracking_assignments after
> @@ -3026,8 +3023,7 @@ Toggle -fvar-tracking-assignments.
>
>   ; Positive if we should track uninitialized variables, negative if
>   ; we should run the var-tracking pass only to discard debug
> -; annotations.  When flag_var_tracking_uninit == AUTODETECT_VALUE it
> -; will be set according to flag_var_tracking.
> +; annotations.
>   fvar-tracking-uninit
>   Common Var(flag_var_tracking_uninit) PerFunction
>   Perform variable tracking and also tag variables that are uninitialized.
> diff --git a/gcc/opts.c b/gcc/opts.c
> index 2116c2991dd..eeb6b1dcc7c 100644
> --- a/gcc/opts.c
> +++ b/gcc/opts.c
> @@ -1353,6 +1353,34 @@ finish_options (struct gcc_options *opts, struct gcc_options *opts_set,
>       SET_OPTION_IF_UNSET (opts, opts_set, flag_vect_cost_model,
>                          VECT_COST_MODEL_CHEAP);
>
> +  /* If the user specifically requested variable tracking with tagging
> +     uninitialized variables, we need to turn on variable tracking.
> +     (We already determined above that variable tracking is feasible.)  */
> +  if (opts->x_flag_var_tracking_uninit == 1)
> +    opts->x_flag_var_tracking = 1;
> +
> +  if (!opts_set->x_flag_var_tracking)
> +    opts->x_flag_var_tracking = optimize >= 1;

That's still not equivalent to the old code for -fvar-tracking-uninit which
sets opts->x_flag_var_tracking to 1 and the old code checked that
for AUTOINIT_VALUE but you override it here for -O0.

> +  if (!opts_set->x_flag_var_tracking_uninit)
> +    opts->x_flag_var_tracking_uninit = opts->x_flag_var_tracking;
> +
> +  if (!opts_set->x_flag_var_tracking_assignments)
> +    opts->x_flag_var_tracking_assignments
> +      = (opts->x_flag_var_tracking
> +        && !(opts->x_flag_selective_scheduling
> +             || opts->x_flag_selective_scheduling2));
> +
> +  if (opts->x_flag_var_tracking_assignments_toggle)
> +    opts->x_flag_var_tracking_assignments = !opts->x_flag_var_tracking_assignments;
> +
> +  if (opts->x_flag_var_tracking_assignments && !opts->x_flag_var_tracking)
> +    opts->x_flag_var_tracking = opts->x_flag_var_tracking_assignments = -1;
> +
> +  if (opts->x_flag_var_tracking_assignments
> +      && (opts->x_flag_selective_scheduling || opts->x_flag_selective_scheduling2))
> +    warning_at (loc, 0,
> +               "var-tracking-assignments changes selective scheduling");
>   }
>
>   #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; }
> diff --git a/gcc/toplev.c b/gcc/toplev.c
> index 81748b1152a..2f13d740b98 100644
> --- a/gcc/toplev.c
> +++ b/gcc/toplev.c
> @@ -1490,8 +1490,8 @@ process_options (bool no_backend)
>         || !dwarf_debuginfo_p ()
>         || debug_hooks->var_location == do_nothing_debug_hooks.var_location)
>       {
> -      if (flag_var_tracking == 1
> -         || flag_var_tracking_uninit == 1)
> +      if ((OPTION_SET_P (flag_var_tracking) && flag_var_tracking == 1)
> +         || (OPTION_SET_P (flag_var_tracking_uninit) && flag_var_tracking_uninit == 1))
>           {
>           if (debug_info_level < DINFO_LEVEL_NORMAL)
>             warning_at (UNKNOWN_LOCATION, 0,
> @@ -1504,6 +1504,7 @@ process_options (bool no_backend)
>         }
>         flag_var_tracking = 0;
>         flag_var_tracking_uninit = 0;
> +      flag_var_tracking_assignments = 0;
>       }
>
>     /* The debug hooks are used to implement -fdump-go-spec because it
> @@ -1512,34 +1513,6 @@ process_options (bool no_backend)
>     if (flag_dump_go_spec != NULL)
>       debug_hooks = dump_go_spec_init (flag_dump_go_spec, debug_hooks);
>
> -  /* If the user specifically requested variable tracking with tagging
> -     uninitialized variables, we need to turn on variable tracking.
> -     (We already determined above that variable tracking is feasible.)  */
> -  if (flag_var_tracking_uninit == 1)
> -    flag_var_tracking = 1;
> -
> -  if (flag_var_tracking == AUTODETECT_VALUE)
> -    flag_var_tracking = optimize >= 1;
> -
> -  if (flag_var_tracking_uninit == AUTODETECT_VALUE)
> -    flag_var_tracking_uninit = flag_var_tracking;
> -
> -  if (flag_var_tracking_assignments == AUTODETECT_VALUE)
> -    flag_var_tracking_assignments
> -      = (flag_var_tracking
> -        && !(flag_selective_scheduling || flag_selective_scheduling2));
> -
> -  if (flag_var_tracking_assignments_toggle)
> -    flag_var_tracking_assignments = !flag_var_tracking_assignments;
> -
> -  if (flag_var_tracking_assignments && !flag_var_tracking)
> -    flag_var_tracking = flag_var_tracking_assignments = -1;
> -
> -  if (flag_var_tracking_assignments
> -      && (flag_selective_scheduling || flag_selective_scheduling2))
> -    warning_at (UNKNOWN_LOCATION, 0,
> -               "var-tracking-assignments changes selective scheduling");
> -
>     if (debug_nonbind_markers_p == AUTODETECT_VALUE)
>       debug_nonbind_markers_p
>         = (optimize
> --
> 2.33.0
>

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH] options: Fix variable tracking option processing.
  2021-10-11 13:05 ` Richard Biener
@ 2021-10-11 13:21   ` Martin Liška
  2021-10-11 13:45     ` Richard Biener
  0 siblings, 1 reply; 20+ messages in thread
From: Martin Liška @ 2021-10-11 13:21 UTC (permalink / raw)
  To: Richard Biener; +Cc: GCC Patches

On 10/11/21 15:05, Richard Biener wrote:
>> +  if (!opts_set->x_flag_var_tracking)
>> +    opts->x_flag_var_tracking = optimize >= 1;
> That's still not equivalent to the old code for -fvar-tracking-uninit which
> sets opts->x_flag_var_tracking to 1 and the old code checked that
> for AUTOINIT_VALUE but you override it here for -O0.
> 

Do you mean the newly added code:

+  if (!opts_set->x_flag_var_tracking)

+    opts->x_flag_var_tracking = optimize >= 1;


that should be equivalent to:

-  if (flag_var_tracking == AUTODETECT_VALUE)

-    flag_var_tracking = optimize >= 1;


? Or do I miss something?

Thanks,
Martin

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH] options: Fix variable tracking option processing.
  2021-10-11 13:21   ` Martin Liška
@ 2021-10-11 13:45     ` Richard Biener
  2021-10-12 15:21       ` Martin Liška
  0 siblings, 1 reply; 20+ messages in thread
From: Richard Biener @ 2021-10-11 13:45 UTC (permalink / raw)
  To: Martin Liška; +Cc: GCC Patches

On Mon, Oct 11, 2021 at 3:21 PM Martin Liška <mliska@suse.cz> wrote:
>
> On 10/11/21 15:05, Richard Biener wrote:
> >> +  if (!opts_set->x_flag_var_tracking)
> >> +    opts->x_flag_var_tracking = optimize >= 1;
> > That's still not equivalent to the old code for -fvar-tracking-uninit which
> > sets opts->x_flag_var_tracking to 1 and the old code checked that
> > for AUTOINIT_VALUE but you override it here for -O0.
> >
>
> Do you mean the newly added code:
>
> +  if (!opts_set->x_flag_var_tracking)
>
> +    opts->x_flag_var_tracking = optimize >= 1;
>
>
> that should be equivalent to:
>
> -  if (flag_var_tracking == AUTODETECT_VALUE)
>
> -    flag_var_tracking = optimize >= 1;
>
>
> ? Or do I miss something?

Yes.  I think to be equivalent it would need to be

   if (!opts_set->x_flag_var_tracking_uninit
       && !opts_set->x_flag_var_tracking)
     opts->x_flag_var_tracking = optimize >= 1;

see how in the old code the order of the tests makes a difference
because we test flag_* we also set.  Please double-check the change
with regard to that.

Btw, I'd be more comfortable when the move of the code would be
independent of the adjustment to not rely on AUTODETECT_VALUE.
Can we do the latter change first (IIRC the former one failed already)?

Richard.

>
> Thanks,
> Martin

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH] options: Fix variable tracking option processing.
  2021-10-11 13:45     ` Richard Biener
@ 2021-10-12 15:21       ` Martin Liška
  2021-10-13  8:47         ` Richard Biener
  0 siblings, 1 reply; 20+ messages in thread
From: Martin Liška @ 2021-10-12 15:21 UTC (permalink / raw)
  To: Richard Biener; +Cc: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 525 bytes --]

On 10/11/21 15:45, Richard Biener wrote:
> Btw, I'd be more comfortable when the move of the code would be
> independent of the adjustment to not rely on AUTODETECT_VALUE.
> Can we do the latter change first (IIRC the former one failed already)?

All right, so I'm doing the first step by eliminating AUTODETECT_VALUE.
Note we can't easily use EnabledBy, the option logic is more complicated (like optimize >= 1).

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

Ready to be installed?
Thanks,
Martin

[-- Attachment #2: 0001-Eliminate-AUTODETECT_VALUE-usage-in-options.patch --]
[-- Type: text/x-patch, Size: 7111 bytes --]

From 55af725e87379695faa4b11321e5b416f2981c74 Mon Sep 17 00:00:00 2001
From: Martin Liska <mliska@suse.cz>
Date: Tue, 12 Oct 2021 14:31:50 +0200
Subject: [PATCH] Eliminate AUTODETECT_VALUE usage in options.

gcc/ChangeLog:

	* common.opt: Stop using AUTODETECT_VALUE as Init value.
	* toplev.c (AUTODETECT_VALUE): Remove it.
	(process_options): Do not compare option values to
	AUTODETECT_VALUE, but use rather OPTION_SET_P macro.
	For flag_var_tracking, do not reset it if it is already set
	based on flag_var_tracking_uninit.
---
 gcc/common.opt | 24 ++++++++++--------------
 gcc/toplev.c   | 32 +++++++++++++-------------------
 2 files changed, 23 insertions(+), 33 deletions(-)

diff --git a/gcc/common.opt b/gcc/common.opt
index 4099effcc80..2b401abdc77 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -3003,19 +3003,16 @@ Common Undocumented Var(flag_use_linker_plugin)
 
 ; Positive if we should track variables, negative if we should run
 ; the var-tracking pass only to discard debug annotations, zero if
-; we're not to run it.  When flag_var_tracking == 2 (AUTODETECT_VALUE) it
-; will be set according to optimize, debug_info_level and debug_hooks
-; in process_options ().
+; we're not to run it.
 fvar-tracking
-Common Var(flag_var_tracking) Init(2) PerFunction
+Common Var(flag_var_tracking) Init(1) PerFunction
 Perform variable tracking.
 
 ; Positive if we should track variables at assignments, negative if
 ; we should run the var-tracking pass only to discard debug
-; annotations.  When flag_var_tracking_assignments ==
-; AUTODETECT_VALUE it will be set according to flag_var_tracking.
+; annotations.
 fvar-tracking-assignments
-Common Var(flag_var_tracking_assignments) Init(2) PerFunction
+Common Var(flag_var_tracking_assignments) PerFunction
 Perform variable tracking by annotating assignments.
 
 ; Nonzero if we should toggle flag_var_tracking_assignments after
@@ -3026,8 +3023,7 @@ Toggle -fvar-tracking-assignments.
 
 ; Positive if we should track uninitialized variables, negative if
 ; we should run the var-tracking pass only to discard debug
-; annotations.  When flag_var_tracking_uninit == AUTODETECT_VALUE it
-; will be set according to flag_var_tracking.
+; annotations.
 fvar-tracking-uninit
 Common Var(flag_var_tracking_uninit) PerFunction
 Perform variable tracking and also tag variables that are uninitialized.
@@ -3190,11 +3186,11 @@ Common Driver RejectNegative JoinedOrMissing
 Generate debug information in default format.
 
 gas-loc-support
-Common Driver Var(dwarf2out_as_loc_support) Init(2)
+Common Driver Var(dwarf2out_as_loc_support)
 Assume assembler support for (DWARF2+) .loc directives.
 
 gas-locview-support
-Common Driver Var(dwarf2out_as_locview_support) Init(2)
+Common Driver Var(dwarf2out_as_locview_support)
 Assume assembler support for view in (DWARF2+) .loc directives.
 
 gcoff
@@ -3248,7 +3244,7 @@ Common Driver JoinedOrMissing
 Generate debug information in default extended format.
 
 ginline-points
-Common Driver Var(debug_inline_points) Init(2)
+Common Driver Var(debug_inline_points)
 Generate extended entry point information for inlined functions.
 
 ginternal-reset-location-views
@@ -3288,7 +3284,7 @@ Common Driver JoinedOrMissing Negative(gvms)
 Generate debug information in extended STABS format.
 
 gstatement-frontiers
-Common Driver Var(debug_nonbind_markers_p) Init(2)
+Common Driver Var(debug_nonbind_markers_p)
 Emit progressive recommended breakpoint locations.
 
 gstrict-dwarf
@@ -3304,7 +3300,7 @@ Common Driver Var(flag_gtoggle)
 Toggle debug information generation.
 
 gvariable-location-views
-Common Driver Var(debug_variable_location_views, 1) Init(2)
+Common Driver Var(debug_variable_location_views, 1)
 Augment variable location lists with progressive views.
 
 gvariable-location-views=incompat5
diff --git a/gcc/toplev.c b/gcc/toplev.c
index 167feac2583..5e0f548f1ea 100644
--- a/gcc/toplev.c
+++ b/gcc/toplev.c
@@ -119,10 +119,6 @@ unsigned int save_decoded_options_count;
 /* Vector of saved Optimization decoded command line options.  */
 vec<cl_decoded_option> *save_opt_decoded_options;
 
-/* Used to enable -fvar-tracking, -fweb and -frename-registers according
-   to optimize in process_options ().  */
-#define AUTODETECT_VALUE 2
-
 /* Debug hooks - dependent upon command line options.  */
 
 const struct gcc_debug_hooks *debug_hooks;
@@ -1490,8 +1486,9 @@ process_options (bool no_backend)
       || !dwarf_debuginfo_p ()
       || debug_hooks->var_location == do_nothing_debug_hooks.var_location)
     {
-      if (flag_var_tracking == 1
-	  || flag_var_tracking_uninit == 1)
+      if ((OPTION_SET_P (flag_var_tracking) && flag_var_tracking == 1)
+	  || (OPTION_SET_P (flag_var_tracking_uninit)
+	      && flag_var_tracking_uninit == 1))
         {
 	  if (debug_info_level < DINFO_LEVEL_NORMAL)
 	    warning_at (UNKNOWN_LOCATION, 0,
@@ -1517,14 +1514,13 @@ process_options (bool no_backend)
      (We already determined above that variable tracking is feasible.)  */
   if (flag_var_tracking_uninit == 1)
     flag_var_tracking = 1;
-
-  if (flag_var_tracking == AUTODETECT_VALUE)
+  else if (!OPTION_SET_P (flag_var_tracking) && flag_var_tracking)
     flag_var_tracking = optimize >= 1;
 
-  if (flag_var_tracking_uninit == AUTODETECT_VALUE)
+  if (!OPTION_SET_P (flag_var_tracking_uninit))
     flag_var_tracking_uninit = flag_var_tracking;
 
-  if (flag_var_tracking_assignments == AUTODETECT_VALUE)
+  if (!OPTION_SET_P (flag_var_tracking_assignments))
     flag_var_tracking_assignments
       = (flag_var_tracking
 	 && !(flag_selective_scheduling || flag_selective_scheduling2));
@@ -1540,21 +1536,19 @@ process_options (bool no_backend)
     warning_at (UNKNOWN_LOCATION, 0,
 		"var-tracking-assignments changes selective scheduling");
 
-  if (debug_nonbind_markers_p == AUTODETECT_VALUE)
+  if (!OPTION_SET_P (debug_nonbind_markers_p))
     debug_nonbind_markers_p
       = (optimize
 	 && debug_info_level >= DINFO_LEVEL_NORMAL
 	 && dwarf_debuginfo_p ()
 	 && !(flag_selective_scheduling || flag_selective_scheduling2));
 
-  if (dwarf2out_as_loc_support == AUTODETECT_VALUE)
-    dwarf2out_as_loc_support
-      = dwarf2out_default_as_loc_support ();
-  if (dwarf2out_as_locview_support == AUTODETECT_VALUE)
-    dwarf2out_as_locview_support
-      = dwarf2out_default_as_locview_support ();
+  if (!OPTION_SET_P (dwarf2out_as_loc_support))
+    dwarf2out_as_loc_support = dwarf2out_default_as_loc_support ();
+  if (!OPTION_SET_P (dwarf2out_as_locview_support))
+    dwarf2out_as_locview_support = dwarf2out_default_as_locview_support ();
 
-  if (debug_variable_location_views == AUTODETECT_VALUE)
+  if (!OPTION_SET_P (debug_variable_location_views))
     {
       debug_variable_location_views
 	= (flag_var_tracking
@@ -1588,7 +1582,7 @@ process_options (bool no_backend)
       debug_internal_reset_location_views = 0;
     }
 
-  if (debug_inline_points == AUTODETECT_VALUE)
+  if (!OPTION_SET_P (debug_inline_points))
     debug_inline_points = debug_variable_location_views;
   else if (debug_inline_points && !debug_nonbind_markers_p)
     {
-- 
2.33.0


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH] options: Fix variable tracking option processing.
  2021-10-12 15:21       ` Martin Liška
@ 2021-10-13  8:47         ` Richard Biener
  2021-10-13 11:59           ` Martin Liška
  0 siblings, 1 reply; 20+ messages in thread
From: Richard Biener @ 2021-10-13  8:47 UTC (permalink / raw)
  To: Martin Liška; +Cc: GCC Patches

On Tue, Oct 12, 2021 at 5:21 PM Martin Liška <mliska@suse.cz> wrote:
>
> On 10/11/21 15:45, Richard Biener wrote:
> > Btw, I'd be more comfortable when the move of the code would be
> > independent of the adjustment to not rely on AUTODETECT_VALUE.
> > Can we do the latter change first (IIRC the former one failed already)?
>
> All right, so I'm doing the first step by eliminating AUTODETECT_VALUE.
> Note we can't easily use EnabledBy, the option logic is more complicated (like optimize >= 1).
>
> Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
>
> Ready to be installed?

Let's split this ;)  The debug_inline_points part is OK.

How can debug_variable_location_views be ever -1?  But the
debug_variable_location_views part looks OK as well.

More or less all parts that have the variable assigned in a single
place in gcc/ are OK (dwarf2out_as_locview_support).  But the
main flag_var_tracking* cases need more thorough view,
maybe we can convert them to single-set code first?

Richard.

> Thanks,
> Martin

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH] options: Fix variable tracking option processing.
  2021-10-13  8:47         ` Richard Biener
@ 2021-10-13 11:59           ` Martin Liška
  2021-10-13 12:50             ` Richard Biener
  0 siblings, 1 reply; 20+ messages in thread
From: Martin Liška @ 2021-10-13 11:59 UTC (permalink / raw)
  To: Richard Biener; +Cc: GCC Patches

On 10/13/21 10:47, Richard Biener wrote:
> Let's split this;)   The debug_inline_points part is OK.

Fine.

> 
> How can debug_variable_location_views be ever -1?  But the
> debug_variable_location_views part looks OK as well.

It comes from here:
gvariable-location-views=incompat5
Common Driver RejectNegative Var(debug_variable_location_views, -1) Init(2)

but it's fine as using -gvariable-location-views=incompat5 leads to
OPTION_SET_P(debug_variable_location_views) == true.

> 
> More or less all parts that have the variable assigned in a single
> place in gcc/ are OK (dwarf2out_as_locview_support).  But the
> main flag_var_tracking* cases need more thorough view,
> maybe we can convert them to single-set code first?

I don't think so, your have code like

       if (flag_var_tracking_assignments_toggle)
	flag_var_tracking_assignments = !flag_var_tracking_assignments;

which makes it more complicated. Or do I miss something?

Cheers,
Martin

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH] options: Fix variable tracking option processing.
  2021-10-13 11:59           ` Martin Liška
@ 2021-10-13 12:50             ` Richard Biener
  2021-10-13 13:12               ` Martin Liška
  0 siblings, 1 reply; 20+ messages in thread
From: Richard Biener @ 2021-10-13 12:50 UTC (permalink / raw)
  To: Martin Liška; +Cc: GCC Patches

On Wed, Oct 13, 2021 at 1:59 PM Martin Liška <mliska@suse.cz> wrote:
>
> On 10/13/21 10:47, Richard Biener wrote:
> > Let's split this;)   The debug_inline_points part is OK.
>
> Fine.
>
> >
> > How can debug_variable_location_views be ever -1?  But the
> > debug_variable_location_views part looks OK as well.
>
> It comes from here:
> gvariable-location-views=incompat5
> Common Driver RejectNegative Var(debug_variable_location_views, -1) Init(2)
>
> but it's fine as using -gvariable-location-views=incompat5 leads to
> OPTION_SET_P(debug_variable_location_views) == true.
>
> >
> > More or less all parts that have the variable assigned in a single
> > place in gcc/ are OK (dwarf2out_as_locview_support).  But the
> > main flag_var_tracking* cases need more thorough view,
> > maybe we can convert them to single-set code first?
>
> I don't think so, your have code like
>
>        if (flag_var_tracking_assignments_toggle)
>         flag_var_tracking_assignments = !flag_var_tracking_assignments;
>
> which makes it more complicated. Or do I miss something?

It does, yes.  But that's a ^ with flag_var_tracking_assignments_toggle ;)

It's also one of the more weird flags, so it could be applied after the
otherwise single set of flag_var_tracking_assignments ...

Richard.

>
> Cheers,
> Martin

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH] options: Fix variable tracking option processing.
  2021-10-13 12:50             ` Richard Biener
@ 2021-10-13 13:12               ` Martin Liška
  2021-10-13 13:29                 ` Richard Biener
  0 siblings, 1 reply; 20+ messages in thread
From: Martin Liška @ 2021-10-13 13:12 UTC (permalink / raw)
  To: Richard Biener; +Cc: GCC Patches

On 10/13/21 14:50, Richard Biener wrote:
> It does, yes.  But that's a ^ with flag_var_tracking_assignments_toggle;)
> 
> It's also one of the more weird flags, so it could be applied after the
> otherwise single set of flag_var_tracking_assignments ...

Well, it's far from being simple.
Can we please make a step and install the patch I sent? I mean the latest
that does the removal of AUTODETECT_VALUE.

Martin

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH] options: Fix variable tracking option processing.
  2021-10-13 13:12               ` Martin Liška
@ 2021-10-13 13:29                 ` Richard Biener
  2021-10-14 11:10                   ` Martin Liška
  0 siblings, 1 reply; 20+ messages in thread
From: Richard Biener @ 2021-10-13 13:29 UTC (permalink / raw)
  To: Martin Liška; +Cc: GCC Patches

On Wed, Oct 13, 2021 at 3:12 PM Martin Liška <mliska@suse.cz> wrote:
>
> On 10/13/21 14:50, Richard Biener wrote:
> > It does, yes.  But that's a ^ with flag_var_tracking_assignments_toggle;)
> >
> > It's also one of the more weird flags, so it could be applied after the
> > otherwise single set of flag_var_tracking_assignments ...
>
> Well, it's far from being simple.
> Can we please make a step and install the patch I sent? I mean the latest
> that does the removal of AUTODETECT_VALUE.

But parts of the patch are not obvious and you've not explained why you
remove all Init(AUTODETECT_VALUE) but for flag_var_tracking you
change it to Init(1).  I count 4 assignments to flag_var_tracking in toplev.c
and one in nvptx.c and c6x.c each.

  if (flag_var_tracking_uninit == AUTODETECT_VALUE)
    flag_var_tracking_uninit = flag_var_tracking;

can probably be handled by EnabledBy, but then we also have

  if (flag_var_tracking_uninit == 1)
    flag_var_tracking = 1;

which suggests the same the other way around.  I guess
positional handling might differ with say
-fvar-tracking -fno-var-tracking-uninit vs. -fno-var-tracking-uninit
-fvar-tracking
when using EnabledBy vs. the "explicit" code.

+  else if (!OPTION_SET_P (flag_var_tracking) && flag_var_tracking)
     flag_var_tracking = optimize >= 1;

I think _this_ should, instead of the Init(1), become an entry in
default_options_table with OPT_LEVELS_1_PLUS.

As said, besides flag_var_* the posted patch looks OK and is good to
commit.

Richard.

>
> Martin

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH] options: Fix variable tracking option processing.
  2021-10-13 13:29                 ` Richard Biener
@ 2021-10-14 11:10                   ` Martin Liška
  2021-10-14 12:07                     ` Richard Biener
  0 siblings, 1 reply; 20+ messages in thread
From: Martin Liška @ 2021-10-14 11:10 UTC (permalink / raw)
  To: Richard Biener; +Cc: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 2230 bytes --]

On 10/13/21 15:29, Richard Biener wrote:
> On Wed, Oct 13, 2021 at 3:12 PM Martin Liška <mliska@suse.cz> wrote:
>>
>> On 10/13/21 14:50, Richard Biener wrote:
>>> It does, yes.  But that's a ^ with flag_var_tracking_assignments_toggle;)
>>>
>>> It's also one of the more weird flags, so it could be applied after the
>>> otherwise single set of flag_var_tracking_assignments ...
>>
>> Well, it's far from being simple.
>> Can we please make a step and install the patch I sent? I mean the latest
>> that does the removal of AUTODETECT_VALUE.
> 
> But parts of the patch are not obvious and you've not explained why you
> remove all Init(AUTODETECT_VALUE) but for flag_var_tracking you
> change it to Init(1).  I count 4 assignments to flag_var_tracking in toplev.c
> and one in nvptx.c and c6x.c each.

All right. So the assignments in these target set flag_var_tracking = 0, which
is fine.

> 
>    if (flag_var_tracking_uninit == AUTODETECT_VALUE)
>      flag_var_tracking_uninit = flag_var_tracking;
> 
> can probably be handled by EnabledBy, but then we also have
> 
>    if (flag_var_tracking_uninit == 1)
>      flag_var_tracking = 1;

Yep, I made:

fvar-tracking
Common Var(flag_var_tracking) PerFunction EnabledBy(fvar-tracking-uninit)

and made fvar-tracking enabled with OPT_LEVELS_1_PLUS.

> 
> which suggests the same the other way around.  I guess

The other way around is problematic as leads to a cycle. I tried adding
a cycle detection in common_handle_option_auto (using a bitmap). But it breaks
case OPT_Wunused, which set sets various sub-values :/


> positional handling might differ with say
> -fvar-tracking -fno-var-tracking-uninit vs. -fno-var-tracking-uninit
> -fvar-tracking

I verified this is fine in debugger.

> when using EnabledBy vs. the "explicit" code.
> 
> +  else if (!OPTION_SET_P (flag_var_tracking) && flag_var_tracking)
>       flag_var_tracking = optimize >= 1;
> 
> I think _this_ should, instead of the Init(1), become an entry in
> default_options_table with OPT_LEVELS_1_PLUS.

Done.

> 
> As said, besides flag_var_* the posted patch looks OK and is good to
> commit.

I'm sending an updated version that survives regression tests.

Thoughts?
Martin

> 
> Richard.
> 
>>
>> Martin

[-- Attachment #2: 0001-Eliminate-AUTODETECT_VALUE-usage-in-options.patch --]
[-- Type: text/x-patch, Size: 8002 bytes --]

From 4d9adc296aa527d9ae504da4271e7293d77bceed Mon Sep 17 00:00:00 2001
From: Martin Liska <mliska@suse.cz>
Date: Tue, 12 Oct 2021 14:31:50 +0200
Subject: [PATCH] Eliminate AUTODETECT_VALUE usage in options.

gcc/ChangeLog:

	* common.opt: Stop using AUTODETECT_VALUE
	and use EnabledBy where possible.
	* opts.c: Enable OPT_fvar_tracking with optimize >= 1.
	* toplev.c (AUTODETECT_VALUE): Remove macro.
	(process_options): Simplify by using EnabledBy and
	OPT_fvar_tracking.  Use OPTION_SET_P macro instead of
	AUTODETECT_VALUE.
---
 gcc/common.opt | 24 ++++++++++--------------
 gcc/opts.c     |  1 +
 gcc/toplev.c   | 41 ++++++++++++++---------------------------
 3 files changed, 25 insertions(+), 41 deletions(-)

diff --git a/gcc/common.opt b/gcc/common.opt
index 1eedfeaf539..a2af7fb36e0 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -3003,19 +3003,16 @@ Common Undocumented Var(flag_use_linker_plugin)
 
 ; Positive if we should track variables, negative if we should run
 ; the var-tracking pass only to discard debug annotations, zero if
-; we're not to run it.  When flag_var_tracking == 2 (AUTODETECT_VALUE) it
-; will be set according to optimize, debug_info_level and debug_hooks
-; in process_options ().
+; we're not to run it.
 fvar-tracking
-Common Var(flag_var_tracking) Init(2) PerFunction
+Common Var(flag_var_tracking) PerFunction EnabledBy(fvar-tracking-uninit)
 Perform variable tracking.
 
 ; Positive if we should track variables at assignments, negative if
 ; we should run the var-tracking pass only to discard debug
-; annotations.  When flag_var_tracking_assignments ==
-; AUTODETECT_VALUE it will be set according to flag_var_tracking.
+; annotations.
 fvar-tracking-assignments
-Common Var(flag_var_tracking_assignments) Init(2) PerFunction
+Common Var(flag_var_tracking_assignments) PerFunction
 Perform variable tracking by annotating assignments.
 
 ; Nonzero if we should toggle flag_var_tracking_assignments after
@@ -3026,8 +3023,7 @@ Toggle -fvar-tracking-assignments.
 
 ; Positive if we should track uninitialized variables, negative if
 ; we should run the var-tracking pass only to discard debug
-; annotations.  When flag_var_tracking_uninit == AUTODETECT_VALUE it
-; will be set according to flag_var_tracking.
+; annotations.
 fvar-tracking-uninit
 Common Var(flag_var_tracking_uninit) PerFunction
 Perform variable tracking and also tag variables that are uninitialized.
@@ -3190,11 +3186,11 @@ Common Driver RejectNegative JoinedOrMissing
 Generate debug information in default format.
 
 gas-loc-support
-Common Driver Var(dwarf2out_as_loc_support) Init(2)
+Common Driver Var(dwarf2out_as_loc_support)
 Assume assembler support for (DWARF2+) .loc directives.
 
 gas-locview-support
-Common Driver Var(dwarf2out_as_locview_support) Init(2)
+Common Driver Var(dwarf2out_as_locview_support)
 Assume assembler support for view in (DWARF2+) .loc directives.
 
 gcoff
@@ -3248,7 +3244,7 @@ Common Driver JoinedOrMissing
 Generate debug information in default extended format.
 
 ginline-points
-Common Driver Var(debug_inline_points) Init(2)
+Common Driver Var(debug_inline_points)
 Generate extended entry point information for inlined functions.
 
 ginternal-reset-location-views
@@ -3288,7 +3284,7 @@ Common Driver JoinedOrMissing Negative(gvms)
 Generate debug information in extended STABS format.
 
 gstatement-frontiers
-Common Driver Var(debug_nonbind_markers_p) Init(2)
+Common Driver Var(debug_nonbind_markers_p)
 Emit progressive recommended breakpoint locations.
 
 gstrict-dwarf
@@ -3304,7 +3300,7 @@ Common Driver Var(flag_gtoggle)
 Toggle debug information generation.
 
 gvariable-location-views
-Common Driver Var(debug_variable_location_views, 1) Init(2)
+Common Driver Var(debug_variable_location_views, 1)
 Augment variable location lists with progressive views.
 
 gvariable-location-views=incompat5
diff --git a/gcc/opts.c b/gcc/opts.c
index fc71b6e4242..65fe192a198 100644
--- a/gcc/opts.c
+++ b/gcc/opts.c
@@ -581,6 +581,7 @@ static const struct default_options default_options_table[] =
     { OPT_LEVELS_1_PLUS, OPT_ftree_sink, NULL, 1 },
     { OPT_LEVELS_1_PLUS, OPT_ftree_slsr, NULL, 1 },
     { OPT_LEVELS_1_PLUS, OPT_ftree_ter, NULL, 1 },
+    { OPT_LEVELS_1_PLUS, OPT_fvar_tracking, NULL, 1 },
 
     /* -O1 (and not -Og) optimizations.  */
     { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_fbranch_count_reg, NULL, 1 },
diff --git a/gcc/toplev.c b/gcc/toplev.c
index 81546b19e91..4f574a5aad3 100644
--- a/gcc/toplev.c
+++ b/gcc/toplev.c
@@ -119,10 +119,6 @@ unsigned int save_decoded_options_count;
 /* Vector of saved Optimization decoded command line options.  */
 vec<cl_decoded_option> *save_opt_decoded_options;
 
-/* Used to enable -fvar-tracking, -fweb and -frename-registers according
-   to optimize in process_options ().  */
-#define AUTODETECT_VALUE 2
-
 /* Debug hooks - dependent upon command line options.  */
 
 const struct gcc_debug_hooks *debug_hooks;
@@ -1483,8 +1479,9 @@ process_options (bool no_backend)
       || !dwarf_debuginfo_p ()
       || debug_hooks->var_location == do_nothing_debug_hooks.var_location)
     {
-      if (flag_var_tracking == 1
-	  || flag_var_tracking_uninit == 1)
+      if ((OPTION_SET_P (flag_var_tracking) && flag_var_tracking == 1)
+	  || (OPTION_SET_P (flag_var_tracking_uninit)
+	      && flag_var_tracking_uninit == 1))
         {
 	  if (debug_info_level < DINFO_LEVEL_NORMAL)
 	    warning_at (UNKNOWN_LOCATION, 0,
@@ -1505,19 +1502,11 @@ process_options (bool no_backend)
   if (flag_dump_go_spec != NULL)
     debug_hooks = dump_go_spec_init (flag_dump_go_spec, debug_hooks);
 
-  /* If the user specifically requested variable tracking with tagging
-     uninitialized variables, we need to turn on variable tracking.
-     (We already determined above that variable tracking is feasible.)  */
-  if (flag_var_tracking_uninit == 1)
-    flag_var_tracking = 1;
-
-  if (flag_var_tracking == AUTODETECT_VALUE)
-    flag_var_tracking = optimize >= 1;
-
-  if (flag_var_tracking_uninit == AUTODETECT_VALUE)
-    flag_var_tracking_uninit = flag_var_tracking;
+  /* One could use EnabledBy, but it would lead to a circular dependency.  */
+  if (!OPTION_SET_P (flag_var_tracking_uninit))
+     flag_var_tracking_uninit = flag_var_tracking;
 
-  if (flag_var_tracking_assignments == AUTODETECT_VALUE)
+  if (!OPTION_SET_P (flag_var_tracking_assignments))
     flag_var_tracking_assignments
       = (flag_var_tracking
 	 && !(flag_selective_scheduling || flag_selective_scheduling2));
@@ -1533,21 +1522,19 @@ process_options (bool no_backend)
     warning_at (UNKNOWN_LOCATION, 0,
 		"var-tracking-assignments changes selective scheduling");
 
-  if (debug_nonbind_markers_p == AUTODETECT_VALUE)
+  if (!OPTION_SET_P (debug_nonbind_markers_p))
     debug_nonbind_markers_p
       = (optimize
 	 && debug_info_level >= DINFO_LEVEL_NORMAL
 	 && dwarf_debuginfo_p ()
 	 && !(flag_selective_scheduling || flag_selective_scheduling2));
 
-  if (dwarf2out_as_loc_support == AUTODETECT_VALUE)
-    dwarf2out_as_loc_support
-      = dwarf2out_default_as_loc_support ();
-  if (dwarf2out_as_locview_support == AUTODETECT_VALUE)
-    dwarf2out_as_locview_support
-      = dwarf2out_default_as_locview_support ();
+  if (!OPTION_SET_P (dwarf2out_as_loc_support))
+    dwarf2out_as_loc_support = dwarf2out_default_as_loc_support ();
+  if (!OPTION_SET_P (dwarf2out_as_locview_support))
+    dwarf2out_as_locview_support = dwarf2out_default_as_locview_support ();
 
-  if (debug_variable_location_views == AUTODETECT_VALUE)
+  if (!OPTION_SET_P (debug_variable_location_views))
     {
       debug_variable_location_views
 	= (flag_var_tracking
@@ -1581,7 +1568,7 @@ process_options (bool no_backend)
       debug_internal_reset_location_views = 0;
     }
 
-  if (debug_inline_points == AUTODETECT_VALUE)
+  if (!OPTION_SET_P (debug_inline_points))
     debug_inline_points = debug_variable_location_views;
   else if (debug_inline_points && !debug_nonbind_markers_p)
     {
-- 
2.33.0


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH] options: Fix variable tracking option processing.
  2021-10-14 11:10                   ` Martin Liška
@ 2021-10-14 12:07                     ` Richard Biener
  2021-10-15 15:22                       ` Martin Liška
  0 siblings, 1 reply; 20+ messages in thread
From: Richard Biener @ 2021-10-14 12:07 UTC (permalink / raw)
  To: Martin Liška; +Cc: GCC Patches

On Thu, Oct 14, 2021 at 1:10 PM Martin Liška <mliska@suse.cz> wrote:
>
> On 10/13/21 15:29, Richard Biener wrote:
> > On Wed, Oct 13, 2021 at 3:12 PM Martin Liška <mliska@suse.cz> wrote:
> >>
> >> On 10/13/21 14:50, Richard Biener wrote:
> >>> It does, yes.  But that's a ^ with flag_var_tracking_assignments_toggle;)
> >>>
> >>> It's also one of the more weird flags, so it could be applied after the
> >>> otherwise single set of flag_var_tracking_assignments ...
> >>
> >> Well, it's far from being simple.
> >> Can we please make a step and install the patch I sent? I mean the latest
> >> that does the removal of AUTODETECT_VALUE.
> >
> > But parts of the patch are not obvious and you've not explained why you
> > remove all Init(AUTODETECT_VALUE) but for flag_var_tracking you
> > change it to Init(1).  I count 4 assignments to flag_var_tracking in toplev.c
> > and one in nvptx.c and c6x.c each.
>
> All right. So the assignments in these target set flag_var_tracking = 0, which
> is fine.
>
> >
> >    if (flag_var_tracking_uninit == AUTODETECT_VALUE)
> >      flag_var_tracking_uninit = flag_var_tracking;
> >
> > can probably be handled by EnabledBy, but then we also have
> >
> >    if (flag_var_tracking_uninit == 1)
> >      flag_var_tracking = 1;
>
> Yep, I made:
>
> fvar-tracking
> Common Var(flag_var_tracking) PerFunction EnabledBy(fvar-tracking-uninit)
>
> and made fvar-tracking enabled with OPT_LEVELS_1_PLUS.
>
> >
> > which suggests the same the other way around.  I guess
>
> The other way around is problematic as leads to a cycle. I tried adding
> a cycle detection in common_handle_option_auto (using a bitmap). But it breaks
> case OPT_Wunused, which set sets various sub-values :/
>
>
> > positional handling might differ with say
> > -fvar-tracking -fno-var-tracking-uninit vs. -fno-var-tracking-uninit
> > -fvar-tracking
>
> I verified this is fine in debugger.
>
> > when using EnabledBy vs. the "explicit" code.
> >
> > +  else if (!OPTION_SET_P (flag_var_tracking) && flag_var_tracking)
> >       flag_var_tracking = optimize >= 1;
> >
> > I think _this_ should, instead of the Init(1), become an entry in
> > default_options_table with OPT_LEVELS_1_PLUS.
>
> Done.
>
> >
> > As said, besides flag_var_* the posted patch looks OK and is good to
> > commit.
>
> I'm sending an updated version that survives regression tests.
>
> Thoughts?

OK.

Thanks,
Richard.

> Martin
>
> >
> > Richard.
> >
> >>
> >> Martin

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH] options: Fix variable tracking option processing.
  2021-10-14 12:07                     ` Richard Biener
@ 2021-10-15 15:22                       ` Martin Liška
  2021-10-19  9:12                         ` Richard Biener
  0 siblings, 1 reply; 20+ messages in thread
From: Martin Liška @ 2021-10-15 15:22 UTC (permalink / raw)
  To: Richard Biener; +Cc: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 515 bytes --]

All right, and there's second part that moves the code
from toplev.c to opts.c (finish_options) as I've done in the original version.

The patch also handles PR102766 where nvptx.c target sets:
debug_nonbind_markers_p = 0;

So the easiest approach is marking the flag as set in global_options_set,
I haven't found a better approach :/ Reason is that nvptx_option_override
is called before finish_options.

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

Ready to be installed?
Thanks,
Martin

[-- Attachment #2: 0001-options-Fix-variable-tracking-option-processing.patch --]
[-- Type: text/x-patch, Size: 4232 bytes --]

From 827647ab23b8bec9d20094e009341598e12a644b Mon Sep 17 00:00:00 2001
From: Martin Liska <mliska@suse.cz>
Date: Thu, 14 Oct 2021 14:57:18 +0200
Subject: [PATCH] options: Fix variable tracking option processing.

	PR debug/102585
	PR bootstrap/102766

gcc/ChangeLog:

	* opts.c (finish_options): Process flag_var_tracking* options
	here as they can be adjusted by optimize attribute.
	* toplev.c (process_options): Remove it here.

gcc/testsuite/ChangeLog:

	* gcc.dg/pr102585.c: New test.
---
 gcc/config/nvptx/nvptx.c        |  1 +
 gcc/opts.c                      | 19 +++++++++++++++++++
 gcc/testsuite/gcc.dg/pr102585.c |  6 ++++++
 gcc/toplev.c                    | 21 +--------------------
 4 files changed, 27 insertions(+), 20 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/pr102585.c

diff --git a/gcc/config/nvptx/nvptx.c b/gcc/config/nvptx/nvptx.c
index 951252e598a..1e4b26381c5 100644
--- a/gcc/config/nvptx/nvptx.c
+++ b/gcc/config/nvptx/nvptx.c
@@ -219,6 +219,7 @@ nvptx_option_override (void)
     flag_toplevel_reorder = 1;
 
   debug_nonbind_markers_p = 0;
+  OPTION_SET_P (debug_nonbind_markers_p) = 1;
 
   /* Set flag_no_common, unless explicitly disabled.  We fake common
      using .weak, and that's not entirely accurate, so avoid it
diff --git a/gcc/opts.c b/gcc/opts.c
index 65fe192a198..bf3a81c287e 100644
--- a/gcc/opts.c
+++ b/gcc/opts.c
@@ -1349,6 +1349,25 @@ finish_options (struct gcc_options *opts, struct gcc_options *opts_set,
     SET_OPTION_IF_UNSET (opts, opts_set, flag_vect_cost_model,
 			 VECT_COST_MODEL_CHEAP);
 
+  /* One could use EnabledBy, but it would lead to a circular dependency.  */
+  if (!OPTION_SET_P (flag_var_tracking_uninit))
+     flag_var_tracking_uninit = flag_var_tracking;
+
+  if (!OPTION_SET_P (flag_var_tracking_assignments))
+    flag_var_tracking_assignments
+      = (flag_var_tracking
+	 && !(flag_selective_scheduling || flag_selective_scheduling2));
+
+  if (flag_var_tracking_assignments_toggle)
+    flag_var_tracking_assignments = !flag_var_tracking_assignments;
+
+  if (flag_var_tracking_assignments && !flag_var_tracking)
+    flag_var_tracking = flag_var_tracking_assignments = -1;
+
+  if (flag_var_tracking_assignments
+      && (flag_selective_scheduling || flag_selective_scheduling2))
+    warning_at (loc, 0,
+		"var-tracking-assignments changes selective scheduling");
 }
 
 #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; }
diff --git a/gcc/toplev.c b/gcc/toplev.c
index 4f574a5aad3..7c0467948f2 100644
--- a/gcc/toplev.c
+++ b/gcc/toplev.c
@@ -1494,6 +1494,7 @@ process_options (bool no_backend)
 	}
       flag_var_tracking = 0;
       flag_var_tracking_uninit = 0;
+      flag_var_tracking_assignments = 0;
     }
 
   /* The debug hooks are used to implement -fdump-go-spec because it
@@ -1502,26 +1503,6 @@ process_options (bool no_backend)
   if (flag_dump_go_spec != NULL)
     debug_hooks = dump_go_spec_init (flag_dump_go_spec, debug_hooks);
 
-  /* One could use EnabledBy, but it would lead to a circular dependency.  */
-  if (!OPTION_SET_P (flag_var_tracking_uninit))
-     flag_var_tracking_uninit = flag_var_tracking;
-
-  if (!OPTION_SET_P (flag_var_tracking_assignments))
-    flag_var_tracking_assignments
-      = (flag_var_tracking
-	 && !(flag_selective_scheduling || flag_selective_scheduling2));
-
-  if (flag_var_tracking_assignments_toggle)
-    flag_var_tracking_assignments = !flag_var_tracking_assignments;
-
-  if (flag_var_tracking_assignments && !flag_var_tracking)
-    flag_var_tracking = flag_var_tracking_assignments = -1;
-
-  if (flag_var_tracking_assignments
-      && (flag_selective_scheduling || flag_selective_scheduling2))
-    warning_at (UNKNOWN_LOCATION, 0,
-		"var-tracking-assignments changes selective scheduling");
-
   if (!OPTION_SET_P (debug_nonbind_markers_p))
     debug_nonbind_markers_p
       = (optimize
-- 
2.33.0


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH] options: Fix variable tracking option processing.
  2021-10-15 15:22                       ` Martin Liška
@ 2021-10-19  9:12                         ` Richard Biener
  2021-10-19  9:34                           ` Martin Liška
  0 siblings, 1 reply; 20+ messages in thread
From: Richard Biener @ 2021-10-19  9:12 UTC (permalink / raw)
  To: Martin Liška; +Cc: GCC Patches

On Fri, Oct 15, 2021 at 5:22 PM Martin Liška <mliska@suse.cz> wrote:
>
> All right, and there's second part that moves the code
> from toplev.c to opts.c (finish_options) as I've done in the original version.
>
> The patch also handles PR102766 where nvptx.c target sets:
> debug_nonbind_markers_p = 0;
>
> So the easiest approach is marking the flag as set in global_options_set,
> I haven't found a better approach :/ Reason is that nvptx_option_override
> is called before finish_options.

So currently nvptx_option_override is called before we do this code
blob (it's called at the beginning of process_options).

Why's the solution not to move this setting to finish_options as well?
(and disabling it along var-tracking when we end with no -g in process_options)

IMHO the target should have the last say, so the hook should be invoked
after we are finished overriding stuff and finish_options should be
_only_ doing diagnostics and disabling stuff we cannot handle.

Richard.

> Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
>
> Ready to be installed?
> Thanks,
> Martin

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH] options: Fix variable tracking option processing.
  2021-10-19  9:12                         ` Richard Biener
@ 2021-10-19  9:34                           ` Martin Liška
  2021-10-19 10:53                             ` Richard Biener
  0 siblings, 1 reply; 20+ messages in thread
From: Martin Liška @ 2021-10-19  9:34 UTC (permalink / raw)
  To: Richard Biener; +Cc: GCC Patches

On 10/19/21 11:12, Richard Biener wrote:
> On Fri, Oct 15, 2021 at 5:22 PM Martin Liška <mliska@suse.cz> wrote:
>>
>> All right, and there's second part that moves the code
>> from toplev.c to opts.c (finish_options) as I've done in the original version.
>>
>> The patch also handles PR102766 where nvptx.c target sets:
>> debug_nonbind_markers_p = 0;
>>
>> So the easiest approach is marking the flag as set in global_options_set,
>> I haven't found a better approach :/ Reason is that nvptx_option_override
>> is called before finish_options.
> 
> So currently nvptx_option_override is called before we do this code
> blob (it's called at the beginning of process_options).

Yes, happens early in process_options.

> 
> Why's the solution not to move this setting to finish_options as well?

I would like to, but the option detection depends on target hooks and some debuginfo
functionality, leading to:

g++ -no-pie   -g   -DIN_GCC -fPIC -DCROSS_DIRECTORY_STRUCTURE   -fno-exceptions -fno-rtti -fasynchronous-unwind-tables -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wno-error=format-diag -Wmissing-format-attribute -Woverloaded-virtual -pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings -fno-common  -DHAVE_CONFIG_H -static-libstdc++ -static-libgcc   -o Tlto-wrapper \
    lto-wrapper.o collect-utils.o ggc-none.o libcommon-target.a libcommon.a ../libcpp/libcpp.a   ../libbacktrace/.libs/libbacktrace.a ../libiberty/pic/libiberty.a ../libdecnumber/libdecnumber.a
/home/marxin/Programming/gcc/gcc/opts.c:1382: error: undefined reference to 'dwarf2out_default_as_loc_support()'
/home/marxin/Programming/gcc/gcc/opts.c:1384: error: undefined reference to 'dwarf2out_default_as_locview_support()'
/home/marxin/Programming/gcc/gcc/opts.c:1409: error: undefined reference to 'targetm'

Or can we do better?

> (and disabling it along var-tracking when we end with no -g in process_options)
> 
> IMHO the target should have the last say, so the hook should be invoked
> after we are finished overriding stuff and finish_options should be
> _only_ doing diagnostics and disabling stuff we cannot handle.

Well, that sounds good, but we are quite far from that :/

Martin

> 
> Richard.
> 
>> Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
>>
>> Ready to be installed?
>> Thanks,
>> Martin


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH] options: Fix variable tracking option processing.
  2021-10-19  9:34                           ` Martin Liška
@ 2021-10-19 10:53                             ` Richard Biener
  2021-10-20  8:51                               ` Martin Liška
  0 siblings, 1 reply; 20+ messages in thread
From: Richard Biener @ 2021-10-19 10:53 UTC (permalink / raw)
  To: Martin Liška; +Cc: GCC Patches

On Tue, Oct 19, 2021 at 11:34 AM Martin Liška <mliska@suse.cz> wrote:
>
> On 10/19/21 11:12, Richard Biener wrote:
> > On Fri, Oct 15, 2021 at 5:22 PM Martin Liška <mliska@suse.cz> wrote:
> >>
> >> All right, and there's second part that moves the code
> >> from toplev.c to opts.c (finish_options) as I've done in the original version.
> >>
> >> The patch also handles PR102766 where nvptx.c target sets:
> >> debug_nonbind_markers_p = 0;
> >>
> >> So the easiest approach is marking the flag as set in global_options_set,
> >> I haven't found a better approach :/ Reason is that nvptx_option_override
> >> is called before finish_options.
> >
> > So currently nvptx_option_override is called before we do this code
> > blob (it's called at the beginning of process_options).
>
> Yes, happens early in process_options.
>
> >
> > Why's the solution not to move this setting to finish_options as well?
>
> I would like to, but the option detection depends on target hooks and some debuginfo
> functionality, leading to:
>
> g++ -no-pie   -g   -DIN_GCC -fPIC -DCROSS_DIRECTORY_STRUCTURE   -fno-exceptions -fno-rtti -fasynchronous-unwind-tables -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wno-error=format-diag -Wmissing-format-attribute -Woverloaded-virtual -pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings -fno-common  -DHAVE_CONFIG_H -static-libstdc++ -static-libgcc   -o Tlto-wrapper \
>     lto-wrapper.o collect-utils.o ggc-none.o libcommon-target.a libcommon.a ../libcpp/libcpp.a   ../libbacktrace/.libs/libbacktrace.a ../libiberty/pic/libiberty.a ../libdecnumber/libdecnumber.a
> /home/marxin/Programming/gcc/gcc/opts.c:1382: error: undefined reference to 'dwarf2out_default_as_loc_support()'
> /home/marxin/Programming/gcc/gcc/opts.c:1384: error: undefined reference to 'dwarf2out_default_as_locview_support()'
> /home/marxin/Programming/gcc/gcc/opts.c:1409: error: undefined reference to 'targetm'
>
> Or can we do better?

Meh ... :/

Well, move the target override hook call down (try to shuffle things
so diagnostics happen after but
"inits" happen before).

> > (and disabling it along var-tracking when we end with no -g in process_options)
> >
> > IMHO the target should have the last say, so the hook should be invoked
> > after we are finished overriding stuff and finish_options should be
> > _only_ doing diagnostics and disabling stuff we cannot handle.
>
> Well, that sounds good, but we are quite far from that :/

Yes, I know...

> Martin
>
> >
> > Richard.
> >
> >> Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
> >>
> >> Ready to be installed?
> >> Thanks,
> >> Martin
>

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH] options: Fix variable tracking option processing.
  2021-10-19 10:53                             ` Richard Biener
@ 2021-10-20  8:51                               ` Martin Liška
  2021-10-21  9:57                                 ` Richard Biener
  0 siblings, 1 reply; 20+ messages in thread
From: Martin Liška @ 2021-10-20  8:51 UTC (permalink / raw)
  To: Richard Biener; +Cc: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 1275 bytes --]

On 10/19/21 12:53, Richard Biener wrote:
> Meh ... :/
> 
> Well, move the target override hook call down (try to shuffle things
> so diagnostics happen after but
> "inits" happen before).

Not so easy. There are direct usages of the hooks
(influences dwarf2out_as_loc_support and dwarf2out_as_locview_support)

   if (!OPTION_SET_P (dwarf2out_as_loc_support))
     dwarf2out_as_loc_support = dwarf2out_default_as_loc_support ();
   if (!OPTION_SET_P (dwarf2out_as_locview_support))
     dwarf2out_as_locview_support = dwarf2out_default_as_locview_support ();

   if (!OPTION_SET_P (debug_variable_location_views))
     {
       debug_variable_location_views
	= (flag_var_tracking
	   && debug_info_level >= DINFO_LEVEL_NORMAL
	   && dwarf_debuginfo_p ()
	   && !dwarf_strict
	   && dwarf2out_as_loc_support
	   && dwarf2out_as_locview_support);
     }

and then the warnings depend on debug_variable_location_views.

I have another attempt which is about moving option detection of debug_nonbind_markers_p
to finish_options. That works fine, except one needs to mark the option as PerFunction.
That's because it depends on 'optimize' and that would trigger:
'global_options are modified in local context' verification error.

What do you think about the patch?
Cheers,
Martin

[-- Attachment #2: 0001-options-Fix-variable-tracking-option-processing.patch --]
[-- Type: text/x-patch, Size: 4878 bytes --]

From 1fbeeb6bb326c6e9e704be7a99b69014b1104fda Mon Sep 17 00:00:00 2001
From: Martin Liska <mliska@suse.cz>
Date: Thu, 14 Oct 2021 14:57:18 +0200
Subject: [PATCH] options: Fix variable tracking option processing.

	PR debug/102585
	PR bootstrap/102766

gcc/ChangeLog:

	* opts.c (finish_options): Process flag_var_tracking* options
	here as they can be adjusted by optimize attribute.
	* toplev.c (process_options): Remove it here.
	* common.opt: Make debug_nonbind_markers_p as PerFunction
	attribute as it depends on optimization level.

gcc/testsuite/ChangeLog:

	* gcc.dg/pr102585.c: New test.
---
 gcc/common.opt                  |  2 +-
 gcc/opts.c                      | 26 ++++++++++++++++++++++++++
 gcc/testsuite/gcc.dg/pr102585.c |  6 ++++++
 gcc/toplev.c                    | 28 +---------------------------
 4 files changed, 34 insertions(+), 28 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/pr102585.c

diff --git a/gcc/common.opt b/gcc/common.opt
index a2af7fb36e0..c4a77f65aa2 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -3284,7 +3284,7 @@ Common Driver JoinedOrMissing Negative(gvms)
 Generate debug information in extended STABS format.
 
 gstatement-frontiers
-Common Driver Var(debug_nonbind_markers_p)
+Common Driver Var(debug_nonbind_markers_p) PerFunction
 Emit progressive recommended breakpoint locations.
 
 gstrict-dwarf
diff --git a/gcc/opts.c b/gcc/opts.c
index 65fe192a198..2dd1e5d5372 100644
--- a/gcc/opts.c
+++ b/gcc/opts.c
@@ -1349,6 +1349,32 @@ finish_options (struct gcc_options *opts, struct gcc_options *opts_set,
     SET_OPTION_IF_UNSET (opts, opts_set, flag_vect_cost_model,
 			 VECT_COST_MODEL_CHEAP);
 
+  /* One could use EnabledBy, but it would lead to a circular dependency.  */
+  if (!OPTION_SET_P (flag_var_tracking_uninit))
+     flag_var_tracking_uninit = flag_var_tracking;
+
+  if (!OPTION_SET_P (flag_var_tracking_assignments))
+    flag_var_tracking_assignments
+      = (flag_var_tracking
+	 && !(flag_selective_scheduling || flag_selective_scheduling2));
+
+  if (flag_var_tracking_assignments_toggle)
+    flag_var_tracking_assignments = !flag_var_tracking_assignments;
+
+  if (flag_var_tracking_assignments && !flag_var_tracking)
+    flag_var_tracking = flag_var_tracking_assignments = -1;
+
+  if (flag_var_tracking_assignments
+      && (flag_selective_scheduling || flag_selective_scheduling2))
+    warning_at (loc, 0,
+		"var-tracking-assignments changes selective scheduling");
+
+  if (!OPTION_SET_P (debug_nonbind_markers_p))
+    debug_nonbind_markers_p
+      = (optimize
+	 && debug_info_level >= DINFO_LEVEL_NORMAL
+	 && dwarf_debuginfo_p ()
+	 && !(flag_selective_scheduling || flag_selective_scheduling2));
 }
 
 #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; }
diff --git a/gcc/toplev.c b/gcc/toplev.c
index cb4f8c470f0..67f921afb3e 100644
--- a/gcc/toplev.c
+++ b/gcc/toplev.c
@@ -1499,6 +1499,7 @@ process_options (bool no_backend)
 	}
       flag_var_tracking = 0;
       flag_var_tracking_uninit = 0;
+      flag_var_tracking_assignments = 0;
     }
 
   /* The debug hooks are used to implement -fdump-go-spec because it
@@ -1507,33 +1508,6 @@ process_options (bool no_backend)
   if (flag_dump_go_spec != NULL)
     debug_hooks = dump_go_spec_init (flag_dump_go_spec, debug_hooks);
 
-  /* One could use EnabledBy, but it would lead to a circular dependency.  */
-  if (!OPTION_SET_P (flag_var_tracking_uninit))
-     flag_var_tracking_uninit = flag_var_tracking;
-
-  if (!OPTION_SET_P (flag_var_tracking_assignments))
-    flag_var_tracking_assignments
-      = (flag_var_tracking
-	 && !(flag_selective_scheduling || flag_selective_scheduling2));
-
-  if (flag_var_tracking_assignments_toggle)
-    flag_var_tracking_assignments = !flag_var_tracking_assignments;
-
-  if (flag_var_tracking_assignments && !flag_var_tracking)
-    flag_var_tracking = flag_var_tracking_assignments = -1;
-
-  if (flag_var_tracking_assignments
-      && (flag_selective_scheduling || flag_selective_scheduling2))
-    warning_at (UNKNOWN_LOCATION, 0,
-		"var-tracking-assignments changes selective scheduling");
-
-  if (!OPTION_SET_P (debug_nonbind_markers_p))
-    debug_nonbind_markers_p
-      = (optimize
-	 && debug_info_level >= DINFO_LEVEL_NORMAL
-	 && dwarf_debuginfo_p ()
-	 && !(flag_selective_scheduling || flag_selective_scheduling2));
-
   if (!OPTION_SET_P (dwarf2out_as_loc_support))
     dwarf2out_as_loc_support = dwarf2out_default_as_loc_support ();
   if (!OPTION_SET_P (dwarf2out_as_locview_support))
-- 
2.33.1


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH] options: Fix variable tracking option processing.
  2021-10-20  8:51                               ` Martin Liška
@ 2021-10-21  9:57                                 ` Richard Biener
  2021-10-21 13:14                                   ` Martin Liška
  0 siblings, 1 reply; 20+ messages in thread
From: Richard Biener @ 2021-10-21  9:57 UTC (permalink / raw)
  To: Martin Liška; +Cc: GCC Patches

On Wed, Oct 20, 2021 at 10:51 AM Martin Liška <mliska@suse.cz> wrote:
>
> On 10/19/21 12:53, Richard Biener wrote:
> > Meh ... :/
> >
> > Well, move the target override hook call down (try to shuffle things
> > so diagnostics happen after but
> > "inits" happen before).
>
> Not so easy. There are direct usages of the hooks
> (influences dwarf2out_as_loc_support and dwarf2out_as_locview_support)
>
>    if (!OPTION_SET_P (dwarf2out_as_loc_support))
>      dwarf2out_as_loc_support = dwarf2out_default_as_loc_support ();
>    if (!OPTION_SET_P (dwarf2out_as_locview_support))
>      dwarf2out_as_locview_support = dwarf2out_default_as_locview_support ();
>
>    if (!OPTION_SET_P (debug_variable_location_views))
>      {
>        debug_variable_location_views
>         = (flag_var_tracking
>            && debug_info_level >= DINFO_LEVEL_NORMAL
>            && dwarf_debuginfo_p ()
>            && !dwarf_strict
>            && dwarf2out_as_loc_support
>            && dwarf2out_as_locview_support);
>      }
>
> and then the warnings depend on debug_variable_location_views.
>
> I have another attempt which is about moving option detection of debug_nonbind_markers_p
> to finish_options. That works fine, except one needs to mark the option as PerFunction.
> That's because it depends on 'optimize' and that would trigger:
> 'global_options are modified in local context' verification error.

That looks like a sensible change anyway - options that depend on options that
are per function have to be per function as well.  It also depends on
flag_selective_scheduling.

But note the checks now happen before

  if (flag_syntax_only)
    {
      write_symbols = NO_DEBUG;
      profile_flag = 0;
    }

  if (flag_gtoggle)
    {
      if (debug_info_level == DINFO_LEVEL_NONE)
        {
          debug_info_level = DINFO_LEVEL_NORMAL;

          if (write_symbols == NO_DEBUG)
            write_symbols = PREFERRED_DEBUGGING_TYPE;
        }
      else
        debug_info_level = DINFO_LEVEL_NONE;
    }

which previously affected debug_nonbind_markers_p.  I think it makes
sense to move
the above to finish_options as well.  I suppose -help doesn't correctly dump
the -g enabled state for -gtoggle at the moment?

Richard.

>
> What do you think about the patch?
> Cheers,
> Martin

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH] options: Fix variable tracking option processing.
  2021-10-21  9:57                                 ` Richard Biener
@ 2021-10-21 13:14                                   ` Martin Liška
  2021-10-21 13:17                                     ` Richard Biener
  0 siblings, 1 reply; 20+ messages in thread
From: Martin Liška @ 2021-10-21 13:14 UTC (permalink / raw)
  To: Richard Biener; +Cc: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 562 bytes --]

On 10/21/21 11:57, Richard Biener wrote:
> which previously affected debug_nonbind_markers_p.  I think it makes
> sense to move
> the above to finish_options as well.  I suppose -help doesn't correctly dump
> the -g enabled state for -gtoggle at the moment?

All right, works for me. The updated patch was tested on nvptx cross compiler
and can bootstrap on x86_64-linux-gnu and survives regression tests.

The -g option is showed in -Q --help=common as:

   -g                          		

So no option value is displayed.

Is the patch fine now?
Thanks,
Martin

[-- Attachment #2: 0001-options-Fix-variable-tracking-option-processing.patch --]
[-- Type: text/x-patch, Size: 5877 bytes --]

From da24e51c8e108373256f1106fe4478b919189c99 Mon Sep 17 00:00:00 2001
From: Martin Liska <mliska@suse.cz>
Date: Thu, 14 Oct 2021 14:57:18 +0200
Subject: [PATCH] options: Fix variable tracking option processing.

	PR debug/102585
	PR bootstrap/102766

gcc/ChangeLog:

	* opts.c (finish_options): Process flag_var_tracking* options
	here as they can be adjusted by optimize attribute.
	Process also flag_syntax_only and flag_gtoggle.
	* toplev.c (process_options): Remove it here.
	* common.opt: Make debug_nonbind_markers_p as PerFunction
	attribute as it depends on optimization level.

gcc/testsuite/ChangeLog:

	* gcc.dg/pr102585.c: New test.
---
 gcc/common.opt                  |  2 +-
 gcc/opts.c                      | 45 +++++++++++++++++++++++++++++++
 gcc/testsuite/gcc.dg/pr102585.c |  6 +++++
 gcc/toplev.c                    | 47 +--------------------------------
 4 files changed, 53 insertions(+), 47 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/pr102585.c

diff --git a/gcc/common.opt b/gcc/common.opt
index a2af7fb36e0..c4a77f65aa2 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -3284,7 +3284,7 @@ Common Driver JoinedOrMissing Negative(gvms)
 Generate debug information in extended STABS format.
 
 gstatement-frontiers
-Common Driver Var(debug_nonbind_markers_p)
+Common Driver Var(debug_nonbind_markers_p) PerFunction
 Emit progressive recommended breakpoint locations.
 
 gstrict-dwarf
diff --git a/gcc/opts.c b/gcc/opts.c
index 65fe192a198..4472cec1b98 100644
--- a/gcc/opts.c
+++ b/gcc/opts.c
@@ -1349,6 +1349,51 @@ finish_options (struct gcc_options *opts, struct gcc_options *opts_set,
     SET_OPTION_IF_UNSET (opts, opts_set, flag_vect_cost_model,
 			 VECT_COST_MODEL_CHEAP);
 
+  /* One could use EnabledBy, but it would lead to a circular dependency.  */
+  if (!OPTION_SET_P (flag_var_tracking_uninit))
+     flag_var_tracking_uninit = flag_var_tracking;
+
+  if (!OPTION_SET_P (flag_var_tracking_assignments))
+    flag_var_tracking_assignments
+      = (flag_var_tracking
+	 && !(flag_selective_scheduling || flag_selective_scheduling2));
+
+  if (flag_var_tracking_assignments_toggle)
+    flag_var_tracking_assignments = !flag_var_tracking_assignments;
+
+  if (flag_var_tracking_assignments && !flag_var_tracking)
+    flag_var_tracking = flag_var_tracking_assignments = -1;
+
+  if (flag_var_tracking_assignments
+      && (flag_selective_scheduling || flag_selective_scheduling2))
+    warning_at (loc, 0,
+		"var-tracking-assignments changes selective scheduling");
+
+  if (flag_syntax_only)
+    {
+      write_symbols = NO_DEBUG;
+      profile_flag = 0;
+    }
+
+  if (flag_gtoggle)
+    {
+      if (debug_info_level == DINFO_LEVEL_NONE)
+	{
+	  debug_info_level = DINFO_LEVEL_NORMAL;
+
+	  if (write_symbols == NO_DEBUG)
+	    write_symbols = PREFERRED_DEBUGGING_TYPE;
+	}
+      else
+	debug_info_level = DINFO_LEVEL_NONE;
+    }
+
+  if (!OPTION_SET_P (debug_nonbind_markers_p))
+    debug_nonbind_markers_p
+      = (optimize
+	 && debug_info_level >= DINFO_LEVEL_NORMAL
+	 && dwarf_debuginfo_p ()
+	 && !(flag_selective_scheduling || flag_selective_scheduling2));
 }
 
 #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; }
diff --git a/gcc/toplev.c b/gcc/toplev.c
index cb4f8c470f0..486bd8804fa 100644
--- a/gcc/toplev.c
+++ b/gcc/toplev.c
@@ -1378,25 +1378,6 @@ process_options (bool no_backend)
 	}
     }
 
-  if (flag_syntax_only)
-    {
-      write_symbols = NO_DEBUG;
-      profile_flag = 0;
-    }
-
-  if (flag_gtoggle)
-    {
-      if (debug_info_level == DINFO_LEVEL_NONE)
-	{
-	  debug_info_level = DINFO_LEVEL_NORMAL;
-
-	  if (write_symbols == NO_DEBUG)
-	    write_symbols = PREFERRED_DEBUGGING_TYPE;
-	}
-      else
-	debug_info_level = DINFO_LEVEL_NONE;
-    }
-
   /* CTF is supported for only C at this time.  */
   if (!lang_GNU_C ()
       && ctf_debug_info_level > CTFINFO_LEVEL_NONE)
@@ -1499,6 +1480,7 @@ process_options (bool no_backend)
 	}
       flag_var_tracking = 0;
       flag_var_tracking_uninit = 0;
+      flag_var_tracking_assignments = 0;
     }
 
   /* The debug hooks are used to implement -fdump-go-spec because it
@@ -1507,33 +1489,6 @@ process_options (bool no_backend)
   if (flag_dump_go_spec != NULL)
     debug_hooks = dump_go_spec_init (flag_dump_go_spec, debug_hooks);
 
-  /* One could use EnabledBy, but it would lead to a circular dependency.  */
-  if (!OPTION_SET_P (flag_var_tracking_uninit))
-     flag_var_tracking_uninit = flag_var_tracking;
-
-  if (!OPTION_SET_P (flag_var_tracking_assignments))
-    flag_var_tracking_assignments
-      = (flag_var_tracking
-	 && !(flag_selective_scheduling || flag_selective_scheduling2));
-
-  if (flag_var_tracking_assignments_toggle)
-    flag_var_tracking_assignments = !flag_var_tracking_assignments;
-
-  if (flag_var_tracking_assignments && !flag_var_tracking)
-    flag_var_tracking = flag_var_tracking_assignments = -1;
-
-  if (flag_var_tracking_assignments
-      && (flag_selective_scheduling || flag_selective_scheduling2))
-    warning_at (UNKNOWN_LOCATION, 0,
-		"var-tracking-assignments changes selective scheduling");
-
-  if (!OPTION_SET_P (debug_nonbind_markers_p))
-    debug_nonbind_markers_p
-      = (optimize
-	 && debug_info_level >= DINFO_LEVEL_NORMAL
-	 && dwarf_debuginfo_p ()
-	 && !(flag_selective_scheduling || flag_selective_scheduling2));
-
   if (!OPTION_SET_P (dwarf2out_as_loc_support))
     dwarf2out_as_loc_support = dwarf2out_default_as_loc_support ();
   if (!OPTION_SET_P (dwarf2out_as_locview_support))
-- 
2.33.1


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH] options: Fix variable tracking option processing.
  2021-10-21 13:14                                   ` Martin Liška
@ 2021-10-21 13:17                                     ` Richard Biener
  0 siblings, 0 replies; 20+ messages in thread
From: Richard Biener @ 2021-10-21 13:17 UTC (permalink / raw)
  To: Martin Liška; +Cc: GCC Patches

On Thu, Oct 21, 2021 at 3:14 PM Martin Liška <mliska@suse.cz> wrote:
>
> On 10/21/21 11:57, Richard Biener wrote:
> > which previously affected debug_nonbind_markers_p.  I think it makes
> > sense to move
> > the above to finish_options as well.  I suppose -help doesn't correctly dump
> > the -g enabled state for -gtoggle at the moment?
>
> All right, works for me. The updated patch was tested on nvptx cross compiler
> and can bootstrap on x86_64-linux-gnu and survives regression tests.
>
> The -g option is showed in -Q --help=common as:
>
>    -g
>
> So no option value is displayed.
>
> Is the patch fine now?

OK.

Thanks,
Richard.

> Thanks,
> Martin

^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2021-10-21 13:17 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-11 11:01 [PATCH] options: Fix variable tracking option processing Martin Liška
2021-10-11 13:05 ` Richard Biener
2021-10-11 13:21   ` Martin Liška
2021-10-11 13:45     ` Richard Biener
2021-10-12 15:21       ` Martin Liška
2021-10-13  8:47         ` Richard Biener
2021-10-13 11:59           ` Martin Liška
2021-10-13 12:50             ` Richard Biener
2021-10-13 13:12               ` Martin Liška
2021-10-13 13:29                 ` Richard Biener
2021-10-14 11:10                   ` Martin Liška
2021-10-14 12:07                     ` Richard Biener
2021-10-15 15:22                       ` Martin Liška
2021-10-19  9:12                         ` Richard Biener
2021-10-19  9:34                           ` Martin Liška
2021-10-19 10:53                             ` Richard Biener
2021-10-20  8:51                               ` Martin Liška
2021-10-21  9:57                                 ` Richard Biener
2021-10-21 13:14                                   ` Martin Liška
2021-10-21 13:17                                     ` Richard Biener

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).