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
