Link to the Compiler Explorer: https://godbolt.org/z/GWbbq3sKK Reproducer: unsigned a; int b; short c; void d(long) { for (bool e = (bool)c - 1; e < (bool)b - 1; e += 0) ; if (a) { for (char f = 0; f < 7; f = 7) for (int g = 0; g < c; g += 10) ; d(-!c); } } Error: >$ g++ -O2 -c func.cpp during GIMPLE pass: evrp func.cpp: In function 'void d(long int)': func.cpp:13:1: internal compiler error: in fill_block_cache, at gimple-range-cache.cc:1277 13 | } | ^ 0x9e79d7 ranger_cache::fill_block_cache(tree_node*, basic_block_def*, basic_block_def*) /testing/gcc/gcc_src_master/gcc/gimple-range-cache.cc:1277 0x1ed1ecd ranger_cache::block_range(irange&, basic_block_def*, tree_node*, bool) /testing/gcc/gcc_src_master/gcc/gimple-range-cache.cc:1107 0x1ecc4f8 gimple_ranger::range_of_expr(irange&, tree_node*, gimple*) /testing/gcc/gcc_src_master/gcc/gimple-range.cc:92 0xee7dff expr_not_equal_to(tree_node*, generic_wide_int<wide_int_storage> const&) /testing/gcc/gcc_src_master/gcc/fold-const.c:10733 0xeec8e3 tree_single_nonzero_warnv_p(tree_node*, bool*) /testing/gcc/gcc_src_master/gcc/fold-const.c:15244 0xeed076 tree_expr_nonzero_p(tree_node*) /testing/gcc/gcc_src_master/gcc/fold-const.c:10706 0xefe7a8 fold_binary_loc(unsigned int, tree_code, tree_node*, tree_node*, tree_node*) /testing/gcc/gcc_src_master/gcc/fold-const.c:12284 0xf0254d fold_build2_loc(unsigned int, tree_code, tree_node*, tree_node*, tree_node*) /testing/gcc/gcc_src_master/gcc/fold-const.c:13774 0x13fe25c simplify_using_initial_conditions(loop*, tree_node*) /testing/gcc/gcc_src_master/gcc/tree-ssa-loop-niter.c:2353 0x1404cd7 simplify_using_initial_conditions(loop*, tree_node*) /testing/gcc/gcc_src_master/gcc/tree-ssa-loop-niter.c:2333 0x1404cd7 number_of_iterations_exit_assumptions(loop*, edge_def*, tree_niter_desc*, gcond**, bool, basic_block_def**) /testing/gcc/gcc_src_master/gcc/tree-ssa-loop-niter.c:2590 0x1405be2 number_of_iterations_exit_assumptions(loop*, edge_def*, tree_niter_desc*, gcond**, bool, basic_block_def**) /testing/gcc/gcc_src_master/gcc/tree-ssa-loop-niter.c:2825 0x1405be2 number_of_iterations_exit(loop*, edge_def*, tree_niter_desc*, bool, bool, basic_block_def**) /testing/gcc/gcc_src_master/gcc/tree-ssa-loop-niter.c:2812 0x135f6f0 number_of_latch_executions(loop*) /testing/gcc/gcc_src_master/gcc/tree-scalar-evolution.c:2813 0x1405ef5 estimate_numbers_of_iterations(loop*) /testing/gcc/gcc_src_master/gcc/tree-ssa-loop-niter.c:4356 0x1408c87 max_loop_iterations(loop*, generic_wide_int<fixed_wide_int_storage<576> >*) /testing/gcc/gcc_src_master/gcc/tree-ssa-loop-niter.c:4462 0x15d2f6f bounds_of_var_in_loop(tree_node**, tree_node**, range_query*, loop*, gimple*, tree_node*) /testing/gcc/gcc_src_master/gcc/vr-values.c:1708 0x1ed6641 fold_using_range::range_of_ssa_name_with_loop_info(irange&, tree_node*, loop*, gphi*, fur_source&) /testing/gcc/gcc_src_master/gcc/gimple-range-fold.cc:1282 0x1ed6e1e fold_using_range::range_of_phi(irange&, gphi*, fur_source&) /testing/gcc/gcc_src_master/gcc/gimple-range-fold.cc:837 0x1ed8e50 fold_using_range::fold_stmt(irange&, gimple*, fur_source&, tree_node*) /testing/gcc/gcc_src_master/gcc/gimple-range-fold.cc:554 Please submit a full bug report, with preprocessed source if appropriate. Please include the complete backtrace with any bug report. See <https://gcc.gnu.org/bugs/> for instructions. GCC version: gcc version 12.0.0 20211107 (9defce622893f87d954e0089e0ea79e1e388a480) (GCC)
Started with r12-4866-gfc4076752067fb40.
The master branch has been updated by Andrew Macleod <amacleod@gcc.gnu.org>: https://gcc.gnu.org/g:0cd653bd2559701da9cc4c9bf51f22bdd68623b5 commit r12-5006-g0cd653bd2559701da9cc4c9bf51f22bdd68623b5 Author: Andrew MacLeod <amacleod@redhat.com> Date: Mon Nov 8 09:32:42 2021 -0500 Don't calculate new values when using the private context callback. When using rangers private callback mechanism to provide context to fold_stmt calls, we are only suppose to be using the cache in read only mode, never calculate new values. gcc/ PR tree-optimization/103122 * gimple-range.cc (gimple_ranger::range_of_expr): Request the cache entry with "calulate new values" set to false. gcc/testsuite/ * g++.dg/pr103122.C: New.
Fixed.