[Bug debug/126801] [13/14/15/16/17 Regression] fvar-tracking-uninit is on by accident via r12-4397

"jakub at gcc dot gnu.org via Gcc-bugs" <[email protected]>
Newsgroups gmane.comp.gcc.bugs
Message-ID <[email protected]/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126801

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
For minimal fix I'd go with
2026-08-19  Jakub Jelinek  <[email protected]>

        PR debug/126801
        * opts.cc (finish_options): Don't set flag_var_tracking_uninit to
        flag_var_tracking by default.  Instead, set flag_var_tracking to
        flag_var_tracking_uninit if the latter was explicitly set.
        * config/darwin.cc (darwin_override_options): Only set
        flag_var_tracking_uninit if it wasn't explicitly set and set it to
        1 rather than flag_var_tracking.  Formatting fix.

--- gcc/opts.cc.jj      2026-08-18 08:47:22.044793076 +0200
+++ gcc/opts.cc 2026-08-19 12:28:11.107209028 +0200
@@ -1499,9 +1499,8 @@ finish_options (struct gcc_options *opts
       opts->x_flag_var_tracking_assignments = 0;
     }

-  /* One could use EnabledBy, but it would lead to a circular dependency.  */
-  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_uninit &&
opts->x_flag_var_tracking_uninit)
+    opts->x_flag_var_tracking = 1;

   if (!opts_set->x_flag_var_tracking_assignments)
     opts->x_flag_var_tracking_assignments
--- gcc/config/darwin.cc.jj     2026-08-17 10:00:21.681856778 +0200
+++ gcc/config/darwin.cc        2026-08-19 12:24:08.235382015 +0200
@@ -3576,12 +3576,13 @@ darwin_override_options (void)
       flag_asynchronous_unwind_tables = 0;
     }

-  if (flag_var_tracking_uninit == 0
+  if (!OPTION_SET_P (flag_var_tracking_uninit)
+      && flag_var_tracking_uninit == 0
       && generating_for_darwin_version >= 9
       && (flag_gtoggle ? (debug_info_level == DINFO_LEVEL_NONE)
-      : (debug_info_level >= DINFO_LEVEL_NORMAL))
+         : (debug_info_level >= DINFO_LEVEL_NORMAL))
       && dwarf_debuginfo_p ())
-    flag_var_tracking_uninit = flag_var_tracking;
+    flag_var_tracking_uninit = 1;

   if (OPTION_SET_P (flag_pie) && flag_pie)
     {

This undoes some of the mistakes made in r12-4397:
1) gcc before that change did
  /* 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;
   which disappeared; i.e. -fvar-tracking-uninit implied -fvar-tracking
2) it removes the bogus assumption that flag_var_tracking_uninit used to be
   AUTODETECT_VALUE by default, it only did in the darwin case
3) fixes the darwin case, so that if one uses explicit -fno-var-tracking-uninit
   then it is honored rather than overridden
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.