Fixes ICE in widening multiplication optimization.
Prevents compiler crash when optimizing certain vector-related multiplication checks.
An Integer Compiler (ICE) in the maybe_optimize_guarding_check function, used during widening multiplication optimizations, has been fixed. The issue occurred when the function was called multiple times within a loop, leading to a buffer overflow in a vector used to store multiplication statements. The fix replaces quick_push with safe_push for adding elements to this vector, preventing the overflow and subsequent crash.
In Details
The widening_mul optimization pass, specifically within maybe_optimize_guarding_check called by match_arith_overflow, was susceptible to an ICE. This was due to repeated calls to mul_stmts.quick_push on a fixed-size auto_vec, leading to buffer overflow when the function was invoked more than twice in a loop context. The fix uses safe_push to ensure that additions to mul_stmts are bounds-checked, preventing the overflow and ICE.
- widening_mul
- An optimization that detects and potentially replaces arithmetic operations with wider types to avoid overflow, or to optimize checks related to such operations.
- ICE
- Internal Compiler Error, a crash within the compiler itself, typically due to a bug in the compiler's logic.
- maybe_optimize_guarding_check
- A function within GCC's tree-optimization passes that checks and potentially optimizes code related to guarding arithmetic operations.
- auto_vec
- A dynamic array or vector class in GCC that manages its own memory, similar to std::vector in C++.
- quick_push
- A method for adding an element to a container (like auto_vec) that assumes there is enough space and does not perform bounds checking, for performance.
- safe_push
- A method for adding an element to a container that includes bounds checking to prevent buffer overflows.