[gcc r16-9300] lto: Fix cache partitioning to handle min_partition_size=0

Michal Jires via Gcc-cvs <[email protected]>
Newsgroups gmane.comp.gcc.cvs
Message-ID <[email protected]>
https://gcc.gnu.org/g:7d496f40df424f19e4591c40e70edfd76df0efed

commit r16-9300-g7d496f40df424f19e4591c40e70edfd76df0efed
Author: Michal Jires <[email protected]>
Date:   Mon May 11 21:11:10 2026 +0200

    lto: Fix cache partitioning to handle min_partition_size=0
    
    Cache partitioning asserts that {min,max}_partition_size parameter
    cannot be 0 to prevent later divisions by zero. This is needlessly
    strict, we can clamp the value to 1 to get reasonable/expected behavior.
    
            PR lto/125257
    
    gcc/lto/ChangeLog:
    
            * lto-partition.cc: Handle min/max_partition_size = 0 for
            cache partitioning.
    
    gcc/testsuite/ChangeLog:
    
            * gcc.dg/lto/pr125257_0.c: New test.
    
    (cherry picked from commit 6a3f305b298438091ef45f92553618d92a47f8dd)

Diff:
---
 gcc/lto/lto-partition.cc              | 6 ++----
 gcc/testsuite/gcc.dg/lto/pr125257_0.c | 6 ++++++
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/gcc/lto/lto-partition.cc b/gcc/lto/lto-partition.cc
index 4812142c48d7..39549702b23b 100644
--- a/gcc/lto/lto-partition.cc
+++ b/gcc/lto/lto-partition.cc
@@ -987,11 +987,9 @@ public:
 
 protected:
   partitioner_base (int64_t min_partition_size, int64_t max_partition_size):
-    min_partition_size (min_partition_size),
-    max_partition_size (max_partition_size)
+    min_partition_size (std::max<int64_t>(min_partition_size, 1)),
+    max_partition_size (std::max<int64_t>(max_partition_size, 1))
   {
-    gcc_assert (min_partition_size != 0);
-    gcc_assert (max_partition_size != 0);
   }
   virtual ~partitioner_base ()
   {}
diff --git a/gcc/testsuite/gcc.dg/lto/pr125257_0.c b/gcc/testsuite/gcc.dg/lto/pr125257_0.c
new file mode 100644
index 000000000000..e3821150a18e
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/lto/pr125257_0.c
@@ -0,0 +1,6 @@
+/* PR lto/125257 */
+/* { dg-lto-do link } */
+/* { dg-lto-options { "-O0 -flto --param=lto-min-partition=0 --param=lto-max-partition=0" } } */
+
+int main() {}
+__attribute__((used)) void foo() {}
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.