Landing: 46ee9bbc9a7d

Project / Subsystem

gcc / gcc/tree-optimization

Date

2026-09-18

Author

Kael Andrew Alonzo Franco

Commit

46ee9bbc9a7d92eb3435999b59c3d8b42254f88a

Source

github

Perf win

No

Breaking

No

All attributes

project
gcc
subsystem
gcc/tree-optimization
patch_id
—
commit_hash
46ee9bbc9a7d92eb3435999b59c3d8b42254f88a
source_type
github
headline
Restrict (X {+,-} M*N) / N optimization to avoid overflow
tldr
Compiler avoids integer overflow by restricting an optimization for division by -1.
author
Kael Andrew Alonzo Franco
outcome
committed
performance_win
false
breaking_change
false
series_id
—
series_parts
[]
tags
  • • optimization
  • • integer overflow
  • • compiler bug
discussion_id_link
—
bugzilla_pr
—
date
2026-09-18T00:00:00.000Z

The compiler’s tree optimizer previously performed an optimization on expressions of the form ((X {+,-} M*N) / N), simplifying it to ((X / N) {+,-} M). However, this transformation can cause integer overflow when X is INT_MIN and N is -1, because INT_MIN / -1 overflows while the original expression may not. This commit adds checks for X > INT_MIN and N != -1 to prevent this overflow.