From 483865e5679c55f8caf2f4b0a70c77b7d7211363 Mon Sep 17 00:00:00 2001
From: Kyrylo Tkachov <ktkachov@nvidia.com>
Date: Thu, 24 Apr 2025 00:34:09 -0700
Subject: [PATCH] opts.cc Fix thinko with default handling of -flto-partition=

This is a thinko in the logic for handling the default -flto-partition=
arguments.  We should override it to balanced only if it stayed as default
up to that point. We should also be testing opts instead of opts_set here.

Bootstrapped and tested on aarch64-none-linux-gnu.

Signed-off-by: Kyrylo Tkachov <ktkachov@nvidia.com>

gcc/

	* opts.cc (finish_options): Check for == against LTO_PARTITION_DEFAULT
	before setting LTO_PARTITION_BALANCED.
---
 gcc/opts.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/opts.cc b/gcc/opts.cc
index 5e7b77dab2f..685c12ababe 100644
--- a/gcc/opts.cc
+++ b/gcc/opts.cc
@@ -1269,7 +1269,7 @@ finish_options (struct gcc_options *opts, struct gcc_options *opts_set,
     SET_OPTION_IF_UNSET (opts, opts_set, flag_reorder_functions, 1);
 
   validate_ipa_reorder_locality_lto_partition (opts, opts_set);
-  if (opts_set->x_flag_lto_partition != LTO_PARTITION_DEFAULT)
+  if (opts->x_flag_lto_partition == LTO_PARTITION_DEFAULT)
     opts_set->x_flag_lto_partition = opts->x_flag_lto_partition = LTO_PARTITION_BALANCED;
 
   /* The -gsplit-dwarf option requires -ggnu-pubnames.  */
-- 
2.44.0

