https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113368

            Bug ID: 113368
           Summary: ICE appearing in 13, not before.
           Product: gcc
           Version: 13.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ephraim.feldblum at redis dot com
  Target Milestone: ---

godbolt: https://godbolt.org/z/qj1WcvxMx

Hi, I've encountered an ICE. It seems to be maybe caused by some combination of
* using gcc 13.1 or 13.2 (at least on godbolt)
* static member init of a std::pair,
* member init of a std::array,
* using std::countr_zero(),
* using a std::optional,
* all when constant folding.
If any of those are changed, the ICE disappears.

--------------------------------------------------------------------------------

input:
#include <array>     // std::array
#include <bit>       // std::countr_zero
#include <optional>  // std::optional
#include <utility>   // std::pair

template <int U>
struct VEB {
   private:
    // doesn't seem to ICE without a pair
    static constexpr std::pair<int, int> G = {1, 1};
    // doesn't seem to ICE without an array, with at least one of the template
params being one of the pair.
    std::array<VEB<G.first>, 1> cluster = {};
    // std::array<VEB<1>, G.second> cluster = {};
   public:
    constexpr void insert(int x) {
        cluster[x].min();
    }
};

template <int U>
    requires(U <= 64)
struct VEB<U> {
   private:
    unsigned cluster = {};
   public:
    // doesn't seem to ICE without an optional
    constexpr std::optional<int> min() const {
        // doesn't seem to ICE without std::countr_zero
        return std::countr_zero(cluster);
    }
};

// doesn't ICE without constant folding. either constexpr or consteval
constexpr auto check_correctness() {
    VEB<65> veb{};
    veb.insert(0);
    return true; // doesn't ICE without the return
};

// alternatively, if consteval, ICEs without return
// consteval auto check_correctness() {
//     VEB<65> veb{};
//     veb.insert(0);
// } // does not need the return to ICE

// doesn't ICE without constant folding, -O or better is required
int main() {
    check_correctness();
}

--------------------------------------------------------------------------------

output:
<source>: In function 'int main()':
<source>:49:22:   in 'constexpr' expansion of 'check_correctness()'
<source>:37:15:   in 'constexpr' expansion of 'veb.VEB<65>::insert(0)'
<source>:17:23:   in 'constexpr' expansion of
'(&((VEB<65>*)this)->VEB<65>::cluster.std::array<VEB<1>,
1>::operator[](((std::array<VEB<1>, 1>::size_type)x)))->VEB<1>::min()'
<source>:50:1:   in 'constexpr' expansion of 'VEB<1>()'
<source>:50:1: internal compiler error: in cxx_eval_component_reference, at
cp/constexpr.cc:4394
   50 | }
      | ^
0x1ce7bde internal_error(char const*, ...)
        ???:0
0x7290fc fancy_abort(char const*, int, char const*)
        ???:0
0x77e950 maybe_constant_value(tree_node*, tree_node*, mce_value)
        ???:0
0x11175b3 walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*, void*),
void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*,
tree_node* (*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*),
void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*))
        ???:0
0x11178a6 walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*, void*),
void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*,
tree_node* (*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*),
void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*))
        ???:0
0x79792c cp_fold_function(tree_node*)
        ???:0
0x7cb265 finish_function(bool)
        ???:0
0x89fd5b c_parse_file()
        ???:0
0x98c5d9 c_common_parse_file()
        ???:0
  • [Bug c++/113368] New: ICE a... ephraim.feldblum at redis dot com via Gcc-bugs

Reply via email to